How to change thumbnail src value in dropzone.js?

Member

by lily , in category: Javascript , 7 months ago

How to change thumbnail src value in dropzone.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 7 months ago

@lily 

To change the thumbnail src value in Dropzone.js, you can use the createThumbnail function provided by Dropzone.js.


Here is an example code snippet on how you can change the thumbnail src value in Dropzone.js:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var myDropzone = new Dropzone("#my-dropzone", {
  url: "/upload",
  maxFilesize: 2,
  acceptedFiles: 'image/*',
  init: function() {
    this.on("addedfile", function(file) {
      // Change the thumbnail src value
      var thumbnail = file.previewElement.querySelector(".dz-image img");
      thumbnail.src = "new_image_url.jpg";
    });
  }
});


In the code above, we are creating a new Dropzone element and initializing it with the init function. Inside the init function, we are using the addedfile event to access the thumbnail element and change its src value to a new image URL.


By using this code snippet, you can dynamically change the thumbnail src value in Dropzone.js.

Related Threads:

How to create thumbnail for uploaded images on dropzone.js?
How to change src function in iframe?
How to test an image src and alt value using capybara?
How to send params value calculated at runtime in dropzone.js?
How to change the default text in dropzone.js?
How to change image upload order in dropzone.js?