From ac4d1bea885df673544060c7bac87cf9f2fff871 Mon Sep 17 00:00:00 2001 From: andyye <63383967+0ev@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:07:11 +0900 Subject: [PATCH 1/4] Add: purl --- .../web/src/components/ModalPopup/ModalMypageModify.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx index dcd267021..b5dfeccd2 100644 --- a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx +++ b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx @@ -70,13 +70,8 @@ const ButtonProfileImage = () => { type: image.type, }, }); - if (data.url && data.fields) { - const formData = new FormData(); - for (const key in data.fields) { - formData.append(key, data.fields[key]); - } - formData.append("file", image); - const res = await axiosOri.post(data.url, formData); + if (data.url) { + const res = await axiosOri.put(data.url, image); if (res.status === 204) { const data2 = await axios({ url: "/users/editProfileImg/done", From 2944418306489a4acc532bec9e720aafb88d2ec7 Mon Sep 17 00:00:00 2001 From: andyye <63383967+0ev@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:19:27 +0900 Subject: [PATCH 2/4] Fix: change request to PUT --- .../src/components/ModalPopup/ModalMypageModify.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx index b5dfeccd2..c11c6df99 100644 --- a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx +++ b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx @@ -71,8 +71,15 @@ const ButtonProfileImage = () => { }, }); if (data.url) { - const res = await axiosOri.put(data.url, image); - if (res.status === 204) { + const res = await axiosOri({ + url: data.url, + method: "put", + headers: { + "Content-Type": image.type, + }, + data: image, + }); + if (res.status === 200) { const data2 = await axios({ url: "/users/editProfileImg/done", method: "get", From babdcaf999f57dd5cb2a68101379867e2145cde9 Mon Sep 17 00:00:00 2001 From: andyye <63383967+0ev@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:30:40 +0900 Subject: [PATCH 3/4] Add send image in chat --- packages/web/src/hooks/chat/useSendMessage.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/web/src/hooks/chat/useSendMessage.tsx b/packages/web/src/hooks/chat/useSendMessage.tsx index 401633095..efa2aa313 100644 --- a/packages/web/src/hooks/chat/useSendMessage.tsx +++ b/packages/web/src/hooks/chat/useSendMessage.tsx @@ -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({ From 2d6bc84d0e3398865695fc6b7b7781503ba6e8ef Mon Sep 17 00:00:00 2001 From: hwmin414 Date: Wed, 13 Mar 2024 01:58:59 +0900 Subject: [PATCH 4/4] fix: remove axios status 200 check, axios automatically checks whether 2xx --- .../ModalPopup/ModalMypageModify.tsx | 20 +++++++++---------- .../web/src/hooks/chat/useSendMessage.tsx | 4 +--- .../web/src/hooks/useTaxiAPI/useAxios.tsx | 2 -- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx index c11c6df99..b0ad3336a 100644 --- a/packages/web/src/components/ModalPopup/ModalMypageModify.tsx +++ b/packages/web/src/components/ModalPopup/ModalMypageModify.tsx @@ -71,7 +71,7 @@ const ButtonProfileImage = () => { }, }); if (data.url) { - const res = await axiosOri({ + await axiosOri({ url: data.url, method: "put", headers: { @@ -79,16 +79,14 @@ const ButtonProfileImage = () => { }, data: image, }); - if (res.status === 200) { - const data2 = await axios({ - url: "/users/editProfileImg/done", - method: "get", - }); - if (data2?.result) { - fetchLoginInfo(); - setProfileAlert("SUCCESS"); - return; - } + const data2 = await axios({ + url: "/users/editProfileImg/done", + method: "get", + }); + if (data2?.result) { + fetchLoginInfo(); + setProfileAlert("SUCCESS"); + return; } } setProfileAlert("FAIL"); diff --git a/packages/web/src/hooks/chat/useSendMessage.tsx b/packages/web/src/hooks/chat/useSendMessage.tsx index efa2aa313..a8f043592 100644 --- a/packages/web/src/hooks/chat/useSendMessage.tsx +++ b/packages/web/src/hooks/chat/useSendMessage.tsx @@ -50,15 +50,13 @@ export default ( }); if (!url || !id) throw new Error(); - const { status: s3Status } = await axiosOri({ + await axiosOri({ url, method: "put", data: file, headers: { "Content-Type": file.type }, }); - if (s3Status !== 204) throw new Error(); - const { result } = await axios({ url: "chats/uploadChatImg/done", method: "post", diff --git a/packages/web/src/hooks/useTaxiAPI/useAxios.tsx b/packages/web/src/hooks/useTaxiAPI/useAxios.tsx index 5204bda8d..2a111153d 100644 --- a/packages/web/src/hooks/useTaxiAPI/useAxios.tsx +++ b/packages/web/src/hooks/useTaxiAPI/useAxios.tsx @@ -42,8 +42,6 @@ const useAxios = () => { `/login?redirect=${encodeURIComponent(currentPath)}` )}` ); - } else if (res.status !== 200) { - throw new Error("Status is not 200!"); } else { if (onSuccess) onSuccess(res.data); return res.data;