Я запустил следующий код и ожидал, что содержимое изображения будет go в месте, указанном в переменной пути, но вместо этого он показывает эту ошибку:
[Error: ENOENT: no such file or directory, open 'C:\Users\Lenovo\Desktop\myCart\public\product_images\5e5dfcdb791fbf15a832b374\image.png'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\Lenovo\\Desktop\\myCart\\public\\product_images\\5e5dfcdb791fbf15a832b374\\image.png'
}
Вот мой код:
First Code:
var fileUpload=require('express-fileupload');
Middleware:
app.use(fileUpload());
Add_Products:
<input type="file" accept="image/*" onchange=" previewFile()" name="image" class="form-control">
Post Request:
if(!req.files){
var imageFile=''
}
if(req.files){
imageFile= req.files.image.name;
}
if(imageFile!=''){
var product_image=req.files.image;
var path='public/product_images/'+product._id+'/'+imageFile;
product_image.mv(path,function(err){
if(err){
console.log(err);
}
})