How to change thumbnail src value in Dropzone.js?

I am using Dropzone.js with jQuery to upload files to the server. Download file Afer. I am creating a server-side name with the current URL.

$('.dropzone').dropzone({
    init: function() {
        this.on('success', function(file) {
            var newname = generateServersideFilename(file.name); // this is my function
            // here I need a help to find the thumbnail <img> to set the 'src' attribute
        }
    }
});

How to find the current thumbnail imgfor setting an attribute src?

+4
source share
3 answers

This worked for me:

$('.dropzone').dropzone({
    init: function() {
        this.on('success', function(file) {
            var newname = generateServersideFilename(file.name); // this is my function
            // changing src of preview element
            file.previewElement.querySelector("img").src = newname;
        }
    }
});

dropzonejs there are some examples of using file.previewElement

+10
source

It could just be

this.on("success", function(file) {
var mydropzone = this;
mydropzone.emit("thumbnail", file, "images/x.jpg");
});

here is the link from dropzone

+3
source
this.on("addedfile", function (file) {

   file.previewElement.querySelector("img").src = "music-box-outline.svg";

});
+1
source

Source: https://habr.com/ru/post/1541826/


All Articles