danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 385 forks source link

Set extraData just before upload #11

Closed zheplusplus closed 9 years ago

zheplusplus commented 9 years ago

hi, thanks for your work.

Is it possible to set extraData just before upload? Like this

$('#dmuploader-div').dmUploader({
    onBeforeUpload: function() {
        $(this).extraData = {someField: $('#some-input').val()};    
    }
})
danielm commented 9 years ago

Thanks for tying the plugin!

Yeah, its an issue that also other people are having as well.

First use the dmuploader.js / dmuploader.min.js from the Git repo, i just commited a small tweak to the code; and then use something like this:

onBeforeUpload: function() {
    $('#drag-and-drop-zone').data('dmUploader').settings.extraData = {
        someField: $('#some-input').val()
    };
}

Not a big fan of this, but it will get the job done until the new version is released with a proper solution for these kind of issues.

Cheers!

autorunman22 commented 5 years ago

Thanks for tying the plugin!

Yeah, its an issue that also other people are having as well.

First use the dmuploader.js / dmuploader.min.js from the Git repo, i just commited a small tweak to the code; and then use something like this:

onBeforeUpload: function() {
    $('#drag-and-drop-zone').data('dmUploader').settings.extraData = {
        someField: $('#some-input').val()
    };
}

Not a big fan of this, but it will get the job done until the new version is released with a proper solution for these kind of issues.

Cheers!

Found the fix for this. Right after the setup, store the instance to a variable for later use. On the next upload, direct access the extraData provided from the settings dnd.data('dmUploader').settings.extraData = extraData

That should dynamically add any extra payloads on your subsequent requests!