0

I would like to get the image file from cloudinary through a public_id (currentPostId)

var currentPostId = this._id;
var file = $('#userimage')[0].files[0];
    if ("undefined" === typeof file) {
      var photo = cloudinary.image(currentPostId+".jpg");
      Cloudinary.upload(photo, {public_id: postProperties._id}, function(err, res) {
        console.log("Upload Error: " + err);
        console.log("Upload Result: " + res);
      });


    }

but I got the following error message:

app.js:372 Uncaught TypeError: cloudinary.image is not a function
    at Object.submit form (app.js:372)
    at blaze.js:3775
    at Function.Template._withTemplateInstanceFunc (blaze.js:3744)
    at Blaze.View.<anonymous> (blaze.js:3774)
    at blaze.js:2617
    at Object.Blaze._withCurrentView (blaze.js:2271)
    at Blaze._DOMRange.<anonymous> (blaze.js:2616)
    at HTMLFormElement.<anonymous> (blaze.js:863)
    at HTMLDivElement.dispatch (jquery.js:4722)
    at HTMLDivElement.elemData.handle (jquery.js:4390)

Is it possible for me to try like this but how could I get the url of my photo?:

var photo = New File('url');
wjy4528
  • 5
  • 2
  • Did you import cloudinary with ``? If not, you'll need to do that. If you did, you'll need `$.cloudinary.image` instead of `cloudinary.image`. – Obsidian Age Jun 28 '17 at 03:26
  • Thanks a lot the error message has disappeared. But how can I convert the img object to file object? Because I can only get a img object from `$.cloudinary.image` but I have no idea why it cannot be uploaded to cloudinary. (Even though I have no error message from Cloudinary upload) How could I make it as a file obejct? – wjy4528 Jun 28 '17 at 04:30
  • `cloudinary.image` returns an HTML element, which is not supported as a `file` parameter in the Cloudinary uploader. As the uploader accepts remote image URLs, you can try using `cloudinary.url` instead to generate a Cloudinary URL and pass that into the uploader. – Roee Ben-Ari Jun 28 '17 at 19:51
  • @RoeeBen-Ari I tried the following code: `var new_url = $.cloudinary.url(currentPostId+"_front_image.jpg"); console.log("check");Cloudinary.upload(new_url, {public_id: postProperties._id+"_front_image"}, function(err, res) { console.log(err); console.log("Upload Result: " + res); });console.log("check");` but I could only get two "check" and the image was not uploaded again. It seems that it didn't enter the cloudinary upload function. (I think the new_url is valid) Could you please help me figure out the reason? – wjy4528 Jun 29 '17 at 00:55
  • What is the value of `new_url`? – Roee Ben-Ari Jul 13 '17 at 14:25

0 Answers0