Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 809
netdjw Avatar asked Dec 07 '22 01:12

netdjw


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

like image 64
YakirNa Avatar answered Dec 19 '22 04:12

YakirNa