netdjw
netdjw

Reputation: 6007

How to change thumbnail src value in Dropzone.js?

I'm using Dropzone.js with jQuery to upload files to the server. Afer file uploaded I'm generating a "server-side" filename 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 can I find the current thumbnail img to set the src attribute?

Upvotes: 5

Views: 19704

Answers (3)

Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

this.on("addedfile", function (file) {

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

});

Upvotes: 2

yogesh singh
yogesh singh

Reputation: 623

This can be simply be

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

here is the link from dropzone

Upvotes: 4

YakirNa
YakirNa

Reputation: 519

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 have few examples of using file.previewElement

Upvotes: 11

Related Questions