2017-06-29 131 views
0

我想通过网址将图像上传到cloudinary。我曾尝试下面的代码:无法上传Cloudinary图像Node.js

 var new_url = $.cloudinary.url(currentPostId+"_front_image.jpg"); 
 
     console.log(new_url); 
 
     console.log("check_first"); 
 
     Cloudinary.upload(new_url, {public_id: postProperties._id+"_front_image"}, function(err, res) { 
 
      console.log(err); 
 
      console.log("Upload Result: " + res); 
 
      console.log("check_second"); 
 
     }); 
 
     console.log("check_third");

我相信NEW_URL是有效的,因为我可以打开它,看到的图像。我做了两个console.log,但是我发现我可以得到“check_first”和“check_third”但不是“check_second”。看来,Cloudinary.upload功能不起作用(我也试过cloudinary.uploader.upload()但仍然失败),并且我的控制台上没有错误消息。我不知道发生了什么事。如果有人能帮助我,我真的很感激。

回答

0

它看起来像你发送一个Cloudinary URL(即http://res.cloudinary.com/<cloud_name>/image/upload/<image_name>给上传者。上载将无法工作,因为没有这样的文件。

尝试将图像本身传递给上传者(无论是从本地路径或从远程位置,任何httphttps URL)

然后上传通话应该是 -

cld.uploader.upload('<image>',function(res){console.log(res);},{public_id:"<public_id>"}) 

有关Cloudinary数据上传选项的详细信息 - http://cloudinary.com/documentation/upload_images#data_upload_options