我创建了一个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
};
出于某种原因,我尝试搜索其他帖子;但我找不到符合我情况的任何东西。如果有人可以帮助...请,我们将不胜感激! 谢谢。