From df9811e32090955839700578fa3feaeef8aefa24 Mon Sep 17 00:00:00 2001 From: Zoonmy Date: Tue, 29 Oct 2024 11:49:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=EC=9A=A9=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=20=EC=8B=9C,=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B6=99?= =?UTF-8?q?=EC=97=AC=EB=84=A3=EA=B8=B0=EC=97=90=EB=8F=84=20=EB=A7=88?= =?UTF-8?q?=ED=81=AC=EB=8B=A4=EC=9A=B4=EC=9C=BC=EB=A1=9C=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85=EB=90=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/EditorPage/MdEditor.jsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/components/EditorPage/MdEditor.jsx b/src/components/EditorPage/MdEditor.jsx index 4fb8018..22e178d 100644 --- a/src/components/EditorPage/MdEditor.jsx +++ b/src/components/EditorPage/MdEditor.jsx @@ -73,6 +73,29 @@ function MdEditor() { }); }; + const handlePasteImage = async (event) => { + const clipboardItems = event.clipboardData.items; + for (let item of clipboardItems) { + if (item.type.includes("image")) { + const file = item.getAsFile(); + if (file) { + try { + const formData = new FormData(); + formData.append("img", file); + const response = await postImageUpload(formData); + const imageUrl = response.data.uploadedUrl; + setPostData((prev) => ({ + ...prev, + content: `${prev.content}\n![image](${imageUrl})`, + })); + } catch (error) { + console.error("Image upload failed:", error); + } + } + } + } + }; + useEffect(() => { setPostData({ language: isEdit ? data?.til.language : "", @@ -134,6 +157,7 @@ function MdEditor() { textareaProps={{ placeholder: "내용을 입력하세요.", }} + onPaste={handlePasteImage} /> setIsModalOpen(true)} />