我创建了一个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
};
我曾尝试搜索其他帖子,原因可能是;但我找不到符合我情况的任何东西。如果有人可以帮助...请,我们将不胜感激!谢谢。
对不起!问题在于CLOUD_NAME配置变量周围带有''标记。
[如果有人遇到类似问题,请尝试删除名称变量周围的引号。