node.js - 使用 Cloudinary 上传图像时,Node js 应用程序不显示错误
问题描述
我在将图像上传到 cloudinary 的 heroku 上部署了我的节点 js 应用程序。它在我的本地机器上正常运行,但是当我在 heroku 上运行它时,我得到 TypeError: Cannot read property 'url' of undefined。请帮助我在这里做错了什么?
app.post('/vehicles', multipartMiddleware, (req, res) => {
cloudinary.v2.uploader.upload(req.files.image.path,
{ width: 300, height: 300, crop: "limit", tags: req.body.tags, moderation: 'manual', timeout: 60000 },
(err, result) => {
console.log(result);
var vehicle = new Vehicle({
name: req.body.name,
price: req.body.price,
transmission: req.body.transmission,
seat_number: req.body.seat_number,
milleage: req.body.milleage,
event: req.body.event,
category: req.body.category,
//Stores the url in a DB for future use
image: result.url,
image_id: result.public_id
});
//Creates a new Vehicle and Add to db
vehicle.save((err, newVehicle) => {
if (err) {
res.redirect("/dashboard")
console.log(err)
} else {
res.redirect("/vehicles")
// console.log(newVehicle);
}
});
}
);
});
解决方案
推荐阅读
- r - R中绘图的密集水平值
- impala - 第一个动作的行号
- angular - Karma + Jasmine + Angular 4 - NullInjectorError: No provider for HttpClient
- php - 使用 Symfony 更新命令中的实体
- angular - 防止更改输入值
- java - Java 使用附加类型参数扩展参数化接口
- asp.net-web-api - OAuthAuthorizationServerProvider 的 invalid_grant
- node.js - DialogFlow NodeJs - 在 webhookClient.setFollowupEvent 之后设置响应消息
- python - 为什么将 dict_keys 转换为列表在 pdb 中不起作用?
- single-sign-on - 使用 simplesaml 为 Zimbra 配置 SSO