在ExpressJS中实现cloudinary时出错
我在使用cloudinary实现我的expressjs代码时遇到问题,在建立要上传的图像的路径时,显示路径未定义。我不明白出了什么问题。
这是我的实施:
错误是在14行,但我不明白为什么:
app.post('/photos', upload.any(), function(solicitud, respuesta){
//console.log(solicitud.body);
if(solicitud.body.password == "emmanuel_1234567"){
var data = {
title: solicitud.body.title,
description: solicitud.body.description,
imageUrl: 'images/carousel/1.jpg'
};
var fotos = new Fotos(data);
console.log(solicitud.files);
cloudinary.uploader.upload(
solicitud.files.photo_image.path, function(result) {
fotos.save(function(error){
console.log('Datos de fotografía guardados satisfactoriamente:');
console.log(fotos);
respuesta.render('index');
});
});
}else{
respuesta.render('photos/new');
console.log('Contraseña incorrecta, por favor, intentelo nuevamente...');
}
});
在终端显示这个:
arleys-mbp:emmanuel_upegui arley_cuadrado$ node app.js
Conexión establecida correctamente!!! :)
[ { fieldname: 'photo_image',
originalname: 'esta.png',
encoding: '7bit',
mimetype: 'image/png',
destination: './uploads',
filename: 'ef11a117af617cac01d78d18e6cd2924',
path: 'uploads/ef11a117af617cac01d78d18e6cd2924',
size: 63050 } ]
TypeError: Cannot read property 'path' of undefined
谢谢你的回答!
回答如下:尝试在文件名后添加扩展名
例如:使用this- cloudinary.uploader.upload(“/ Users / Downloads / sample.jpg”,function(result){console.log(result)});
而不是this- cloudinary.uploader.upload(“/ Users / Downloads / sample”,function(result){console.log(result)});