节点 Cloudinary 图片上传在 Heroku 中不起作用
Node Cloudinary Picture Upload not Working in Heroku
我创建了一个 SNS 网络应用程序(使用 node.js),人们可以在其中将图片(使用 cloudinary)上传到 collections。
该应用程序在我用于编写代码的 cloud-based 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 配置变量周围有 '' 标记。
如果有人遇到类似问题,请尝试删除 name 变量两边的引号。
我创建了一个 SNS 网络应用程序(使用 node.js),人们可以在其中将图片(使用 cloudinary)上传到 collections。 该应用程序在我用于编写代码的 cloud-based 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 配置变量周围有 '' 标记。
如果有人遇到类似问题,请尝试删除 name 变量两边的引号。