Lepozepo / cloudinary

MIT License
94 stars 42 forks source link

[Object object] returned from callback #40

Open generalleger opened 9 years ago

generalleger commented 9 years ago

Putting this here for anyone who comes across this issue:

I am not a coffeescript user, so I usually just go to js2.coffee to translate example code from coffeescript to JS. Well, that works 99% of the time. This time it caused me a silly error that took me way too long to identify.

The example coffeescript code for the Meteor event code translates to this:

Template.yourtemplate.events({
  "change input[type='file']": function(e) {
    var files;
    files = e.currentTarget.files;
    return Cloudinary.upload(files, {
      folder: "secret"
    }, function(err, res) {
      console.log("Upload Error: " + err);
      return console.log("Upload Result: " + res);
    });
  }
});

The problem was that the in the console.log method, the translator was using + instead of ,, and when you try to display an object in a string, it produced the [Object object] output. Simply change the +'s into ,'s and you'll be good.

Lepozepo commented 9 years ago

Thank you for adding that!

generalleger commented 9 years ago

Sure thing, it was driving me bananas because I thought the callback was broken... felt stupid to see it was just the console log statement. Thanks for this great package!

greatramu commented 8 years ago

adding my 2 cents to this. In case you do not have any optional parameters, just pass an empty object. Or else, the callback will not be called

    Cloudinary.upload(files, {}, function(err, res) {
        console.log("Upload Error: " , err);
        return console.log("Upload Result: " , res);