I am building a simple blogging website and was trying to implement image tool of editor.js but got this error. I am using typescript and react.
Error i am encountering.
Image Tool: uploading failed because of TypeError: Cannot read properties of undefined (reading 'success')
at _P.onUpload (image.mjs:1118:7)
at B.onUpload (image.mjs:931:29)
at image.mjs:771:12
Image config tool
image:{
class:ImageTool,
config:{
uploader:{
async uploadByFile(file:any){
const formData = new FormData();
formData.append("file",file);
const resp = await axios.post(
`http://192.168.1.227:5000/api/blog-image`,
formData,{
headers: {
'Authorization': `${authKey}`
}
}
);
if(resp.data.success === 1){
return resp.data;
}
}
}
}
}
on success the resp.data
looks like this
{
"data": {
"success": 1,
"file": {
"url": "D:\Y-3\AD\Group\BisleriumBlogs\BisleriumBlogs\Public/Images/Rectangle 2852.png"
}
},
"message": "Blog image added successfully!"
}
How to solve this??
I tried to sending the return manually. But couldn’t figure out at all.