I'm trying to upload images to my database using the rich-markdown-editor, however, everytime I console.log() my uploads/uploadObject route, nothing gets retrieved; I'm using express-fileupload and it has always worked before, however, since I decided to use said text-editor, everything started to go downhill.
Here it is the code I use for my uploading of files:
exports.uploadObject = asyncHandler(async (req, res, next) => {
console.log('Req body:', req.body)
console.log('Req files:', req.files)
console.log('Req query:', req.query)
const file = await cloudinary.uploader.upload(req.files)
res.status(201).json({
success: true,
data: {
insecure_url: file.url,
secure_url: file.secure_url,
},
})
})
I have put, several methods to see if the file is actually received on my backend but no success so far. Yes, I tried to send it via query, ?uploadedFile=${file}....did not work either.
Here it is the code from my textEditor component
<Editor
name={name}
id={id}
dark={true}
defaultValue={text}
uploadImage={async (e) => {
try {
const file = await resizeFile(e) // returns base64 string
const res = await axios.get(`/uploads/uploadObject`, file)
console.log('Upload action', res)
} catch (err) {
// const error = err.response.data.message;
const error = err?.response?.data?.error?.errors
const errors = err?.response?.data?.errors
if (error) {
// dispatch(setAlert(error, 'danger'));
error &&
Object.entries(error).map(([, value]) => toast.error(value.message))
}
if (errors) {
errors.forEach((error) => toast.error(error.msg))
}
toast.error(err?.response?.statusText)
return {
msg: err?.response?.statusText,
status: err?.response?.status,
}
}
}}
onChange={(e) => {
setBlogData({
...blogData,
text: e(),
})
}}
readOnly={isReadOnly}
/>
If you guys could give me an insight into what the problem might be, I would be very thankful.