Skip to content

Commit

Permalink
Add send image in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
predict-woo committed Jan 23, 2024
1 parent 3e14a51 commit 8877526
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/hooks/chat/useSendMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ export default (
if (!file) throw new Error();

isSendingMessage.current = true;
const { url, fields, id } = await axios({
const { url, id } = await axios({
url: "chats/uploadChatImg/getPUrl",
method: "post",
data: { roomId, type: file.type },
});
if (!url || !fields || !id) throw new Error();
if (!url || !id) throw new Error();

const { status: s3Status } = await axiosOri({
url,
method: "put",
data: file,
headers: { "Content-Type": file.type },
});

const formData = new FormData();
for (const key in fields) formData.append(key, fields[key]);
formData.append("file", file);
const { status: s3Status } = await axiosOri.post(url, formData);
if (s3Status !== 204) throw new Error();

const { result } = await axios({
Expand Down

0 comments on commit 8877526

Please sign in to comment.