Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to add an existing image to my dropzone programatically, using the dropzone.js FAQ as a guide:

    // Add the existing image if it's there.
    // headerDropzone is my dropzone (debug shows it as existing and initialized at this point.
    var on_load_header = $( '[name="on_load_header_image"]' ).val();
    var on_load_header_path = $( '[name="on_load_header_image_path"]' ).val();

    if ( on_load_header ) {

        // Hardcoded size value is just for testing, see my second question below.
        var on_load_header_data = { name: on_load_header, size: 12345 };

        // Call the default addedfile event handler
        headerDropzone.options.addedfile.call( headerDropzone, on_load_header_data );

        // And optionally show the thumbnail of the file:
        headerDropzone.options. thumbnail.call( headerDropzone, on_load_header_data, on_load_header_path);

     }

My first problem is that this is just not working. The addedfile event doesn't fire (or at least the addedfile handler in headerDropzone never fires), same goes for thumbnail.

My second problem/question is: do I have to provide the file size? I could get it server side, but I'd rather not do it if I don't actually need to.

Thanks in advance to anyone who can help.

share|improve this question

1 Answer

up vote 2 down vote accepted

See if the functions headerDropzone.options.addedfile and headerDropzone.options.thumbnail are actually defined. It should work the way you did it, but without further info it's difficult to tell what's wrong.

About the filesize: No, it's not necessary to actually provide the accurate filesize. It's just that Dropzone automatically displays the filesize. If you don't care if some false filesize is displayed then you can just provide some random number or 0. Otherwise you might want to hide the filesize with CSS, or with JS after you add it. (The element in question has the class dz-size.

The JavaScript version of it would look something like this:

var fileSizeElement = on_load_header_data.previewElement.querySelector(".dz-size");
fileSizeElement.parentNode.removeChild(fileSizeElement);
share|improve this answer
1  
Thanks so much for your answer. I went with a different approach that was a better fit for my particular application. Thanks for dropzone, btw, it's a pleasure to work with. – Jesse Rosato Jul 11 at 23:17
Thank you, great to hear. – enyo Jul 12 at 17:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.