Skip to content Skip to sidebar Skip to footer

Adding Image Id To Each Image In Preview Template In Dropzone .js

I just want to add image id to each image that are uploaded using dropzone.js currently preview template is like this

Solution 1:

This code get all images from the server and initialize the dropzone container. I hope this help you

// Initialize dropzone
init: function() {
   thisDropzone = this;
   // Call server to get all images in JSON format {id, filename, imagesize}
   $.get("get-all-images", function(data) {
        $.each(data.data, function(key,value){

           var mockFile = { name: value.filename, size: value.imagesize };
           thisDropzone.options.addedfile.call(thisDropzone, mockFile);
           thisDropzone.options.thumbnail.call(thisDropzone, mockFile, value.file);

           // On the created element added the id property 
           $(mockFile.previewElement).prop('id', value.id);
       });
   });
}

Post a Comment for "Adding Image Id To Each Image In Preview Template In Dropzone .js"