Lepozepo / cloudinary

MIT License
94 stars 42 forks source link

Upload without using helper #25

Open sangyoo91 opened 9 years ago

sangyoo91 commented 9 years ago

How can I upload an image without using the helper in the package with form data?

This is a shortened code that I have to first show the image in html5 before upload.

I am using cropper.js to crop the image first, before sending it to cloudinary with the formData.

// Deleted Cropper code.
function readURL(input) {
  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.readAsDataURL(input.files[0]);

    reader.onload = function (event) {
      $('#avatar-preview').attr('src', event.target.result);
    }
  }
}

Template.foo.events({
  'click .upload': function () {
    // I want to initiate uploading photo from $('#avatar-preview > img') with form data. Here
  }
});
Lepozepo commented 9 years ago

Hi! You would have to do something kind of like this:

                Meteor.call("cloudinary_upload",reader.result,options,function(err,res){
                    if(err){
                        _cloudinary.remove(options.db_id);
                        console.log(err);
                    } else {
                        callback && callback(res);
                    }
                });

That is what we're calling when we're using the normal "cloudinary_upload" method. I also have a "cloudinary_upload_stream" method that should work but I'm not certain. Have a look at this file.

sangyoo91 commented 9 years ago

@Lepozepo Thank you! Is it possible to add form data to cloudinary_upload call?

Lepozepo commented 9 years ago

Hey! I completely revamped the code. It is much more efficient now! Although it still needs a bit more work for auth. It should be less confusing to build on it now that there is no helper.