diff --git a/src/apis/createImg.jsx b/src/apis/createImg.jsx new file mode 100644 index 0000000..66fc47e --- /dev/null +++ b/src/apis/createImg.jsx @@ -0,0 +1,21 @@ +import axios from "axios"; + +const createImg = async (csrfToken, formData) => { + try { + const serverResponse = await axios.post(`${process.env.REACT_APP_HOST_URL}/v1/images`, formData, { + withCredentials: true, + headers: { + "X-CSRF-TOKEN": csrfToken, + "Content-Type": "multipart/form-data", + }, + }); + console.log("이미지가 정상적으로 추가되었음", serverResponse); + + return serverResponse.data.imageUrl; + } catch (error) { + console.error("이미지 추가 실패:", error); + throw error; + } +}; + +export default createImg; diff --git a/src/homepage/component/goals/CreateGoalModal/CreateGoalModal.jsx b/src/homepage/component/goals/CreateGoalModal/CreateGoalModal.jsx index ef07297..9507c0e 100644 --- a/src/homepage/component/goals/CreateGoalModal/CreateGoalModal.jsx +++ b/src/homepage/component/goals/CreateGoalModal/CreateGoalModal.jsx @@ -10,7 +10,7 @@ import { Toggle } from "./Toggle"; import { CSSTransition, TransitionGroup } from "react-transition-group"; import updateGoal from "../../../../apis/updateGoal"; import { fi } from "date-fns/locale"; -import createImg from "../../../../apis/\bcreateImg"; +import createImg from "../../../../apis/createImg"; const formatDate = (date) => { const year = date.getFullYear();