【发布时间】:2020-03-22 18:17:49
【问题描述】:
我创建了一个 SNS Web 应用程序(使用 node.js),人们可以将图片(使用 cloudinary)上传到集合中。 该应用程序在我用于编写代码的基于云的 IDE 上完美运行;但是,将其推送到 heroku 后,图像上传不再有效。我的控制台中没有收到任何错误消息,即使我认为它应该是 console.logging 它,但是错误闪烁发生并且图像没有上传。
这是我的代码:
router.post("/", middleware.isLoggedIn, upload.single('image'), function(req, res){
cloudinary.v2.uploader.upload(req.file.path, function(err, result) {
if (err) {
//if error
console.log(err.message);
req.flash("error", "Can't upload image, try again later.");
return res.redirect("back");
}
//else
// add cloudinary url for the image to the campground object under image property
req.body.image = result.secure_url;
req.body.imageId = result.public_id;
// add author to campground
req.body.author = {
id: req.user._id,
username: req.user.username
};
我尝试搜索其他帖子可能是出于某种原因;但我找不到任何符合我情况的东西。如果有人可以帮助...请,您的建议将不胜感激! 谢谢。
【问题讨论】:
标签: node.js heroku image-uploading cloudinary