最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change thumbnail src value in Dropzone.js? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked May 23, 2014 at 20:28 netdjwnetdjw 6,00726 gold badges106 silver badges185 bronze badges 1
  • Not the best way, but working: $('span:contains("'+file.name+'")').closest('.dz-preview').find('img').attr('src', newname); - If you know a better way, please share. – netdjw Commented May 23, 2014 at 21:24
Add a comment  | 

3 Answers 3

Reset to default 11

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

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

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

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

});
发布评论

评论列表(0)

  1. 暂无评论