[1.0.4] #29
@@ -10,6 +10,7 @@ import Table from "@editorjs/table";
|
|||||||
import CodeTool from "@editorjs/code";
|
import CodeTool from "@editorjs/code";
|
||||||
import Embed from "@editorjs/embed";
|
import Embed from "@editorjs/embed";
|
||||||
import Delimiter from "@editorjs/delimiter";
|
import Delimiter from "@editorjs/delimiter";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createBlogApi,
|
createBlogApi,
|
||||||
@@ -23,6 +24,7 @@ import {Input} from "@/components/ui/input";
|
|||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
|
|
||||||
export default function BlogEditorPage() {
|
export default function BlogEditorPage() {
|
||||||
|
const baseURL = import.meta.env.VITE_API_URL;
|
||||||
const {id} = useParams();
|
const {id} = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -79,12 +81,41 @@ export default function BlogEditorPage() {
|
|||||||
config: {
|
config: {
|
||||||
uploader: {
|
uploader: {
|
||||||
uploadByFile: async (file: File) => {
|
uploadByFile: async (file: File) => {
|
||||||
const res = await uploadImageApi(file);
|
if (file.size > 5 * 1024 * 1024) {
|
||||||
|
alert("File is too large (Max 5MB)");
|
||||||
|
return {success: 0, file: {url: ""}};
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
formData.append("folderPath", "/blog");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post(
|
||||||
|
`${baseURL}/upload`,
|
||||||
|
formData,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: 1,
|
success: 1,
|
||||||
file: {url: res.file.url},
|
file: {url: response.data.fileUrl},
|
||||||
};
|
};
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("EditorJS Image Upload Error:", e);
|
||||||
|
const errorMessage =
|
||||||
|
e.response?.data?.error || e.message || "Upload failed";
|
||||||
|
alert(`Upload Error: ${errorMessage}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: 0,
|
||||||
|
file: {url: ""},
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user