Cannot read property 'path' of undefined
I'm getting this error even though multer logged the correct req.file.
[0] req.file: {“fieldname”:“src”,“originalname”:“Pexels Videos 2098989.mp4”,“encoding”:“7bit”,“mimetype”:“video/mp4”,“destination”:“C:\xampp\htdocs\mern_redux_ntv\frontside\public\uploads”,“filename”:“a3f5f60b52b20725b2c48a8ea08895cc”,“path”:“C:\xampp\htdocs\mern_redux_ntv\frontside\public\uploads\a3f5f60b52b20725b2c48a8ea08895cc”,“size”:112958753}
Thanks for your answer.
Best Roman
That is my code:
const upload = require("../utils/multer");
const cloudinary = require("../utils/cloudinary");
const path = require("path");
//create
const uploadVideo = upload.single("src");
router.post("/", verifyTokenAndAuthorization, async (req,res,next)=>{
uploadVideo(req,res, function(err){
if(err){
console.log(err);
return;
} else{
console.log('req.file:', JSON.stringify(req.file));
next();
}
})
try{
const result = cloudinary.uploader.upload_large(req.file.path, {
upload_preset: "Mern_redux-practice",
resource_type: "video",
}
);
const newVideos= new Videos({
cloudinary_id: result.public_id,
ressort: req.body.ressort,
theme: req.body.theme,
title:req.body.title,
src: result.secure_url,
})
const savedVideos= await newVideos.save();
res.status(200).json(savedVideos);
} catch(error){
res.status(403)
console.log(error)
throw new Error("Action failed");
}
});
-
Hi Roman,
The target file in the path may need to have the file extension in addition to the file (otherwise, it is not really available). In addition to the need to install the path package into your project environment, you can also see other recommendations found in this link.
Hope this helps.
0 -
Thanks for response Eric. No, like it is shown, multer shows the exact path and the path package is default so you not have to install it. Their must be some discord between multer and cloudinary. I could imagine that it is a time problem but I tried everything out, what could handle this. By the way, Images are uploaded without any problem.
0 -
Hi Roman, thanks for the clarification. As the uploading process is successful, accessing the images from your Media Library account can be done by using the delivery URL of the asset. Generating the URL can be done by using one of our SDKs. You could refer to this sample project using Node JS (see source here in Github). Additionally, as the Multer-Storage-Cloudinary is a third-party application, you could also see some other references as described in this document.
Please have a look and see if that could help to clarify the implementations. Thanks.
0
Post is closed for comments.
Comments
3 comments