Send custom data with dropzone.js on each File Upload Send custom data with dropzone.js on each File Upload codeigniter codeigniter

Send custom data with dropzone.js on each File Upload


I got it.This is what I had to use

myDropzone.on('sending', function(file, xhr, formData){    formData.append('userName', 'bob');});


Abhinav has the right and working answer I only want to give a second option to use it in the options object (for example if you have multiple Dropzone sections on one page.)

myDropzone.options.dropzoneDivID = {    sending: function(file, xhr, formData){        formData.append('userName', 'Bob');    }};


In case you have a nested payload object - e.g. to add a name to your file and your api only accepts something like this

{    someParameter: {        image: <my-upload-file>,        name: 'Bob'    }}

your dropzone setup would look like this

var myDropzone     = new Dropzone("div#attachment", {     url: uploadFilePath,    paramName: 'someParameter[image]'});myDropzone.on('sending', function(file, xhr, formData){    formData.append('someParameter[image]', file);    formData.append('someParameter[userName]', 'bob');});

I only added this as there was no example for nested parameters documented since now.