In my src directory, there is a temp file, using multer I upload the file in the temp file but I cannot upload the file in cloudinary. Why it happen please help me, please help me
Here is my code:
console.log("file detail:", JSON.stringify(req.file))
//output {"fieldname":"avatar","originalname":"Screenshot 2024-07-27 004034.png","encoding":"7bit","mimetype":"image/png","destination":"uploads/","filename":"Screenshot 2024-07-27 004034.png","path":"uploadsScreenshot 2024-07-27 004034.png","size":474631}
if (req.file) {
try {
const result = await cloudinary.v2.uploader.upload(req.file.path, {
folder: "learnify",
width: 250,
height: 250,
gravity: "faces",
crop: "fill",
}).then(result=>console.log('RESULT',result)).catch(error => {
console.error(error.message)});// For result i get undefined
if (result) {
user.avatar.public_id = result.public_id;
user.avatar.secure_url = result.secure_url;
// Remove file from server
fs.rm(`../temp/${req.file.filename}`);
}
} catch (error) {
return next(new AppError("File not upload, please try again", 500));
}
I am trying to upload file to cloudnary from temp file…