Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery file upload doesn't submit extra parameters

I need to use the formData parameter available in the jQuery File Upload control to send additional data to the server on submit. The default implementation for formData is to invoke a function that grabs all controls in the form and serializes them to an array (using the jQuery serializeArray() method).

I have controls in my form, but when the file is uploaded, I am not getting any additional data. When I inspect via Fiddler, there is nothing in the request that shows these form fields are being submitted.

Is there something additional that needs to be done to get these to submit?

Btw, these two links discuss formData...

https://github.com/blueimp/jQuery-File-Upload/wiki/Submit-files-asynchronously https://github.com/blueimp/jQuery-File-Upload/wiki/Options ...for this one search the page for formData.

For what its worth, the multipart option is set to true.

like image 815
John Livermore Avatar asked Mar 26 '13 21:03

John Livermore


2 Answers

I also needed to pass an extra parameter and here is what i used :

$('#fileupload').fileupload({
    formData: {
                    param1: 'test'
                    ,param2: "value2"
                    ,param3: "yasseshaikh"
              }
});

The formData option can be used to set additional form data programmatically.

like image 79
Yasser Shaikh Avatar answered Nov 05 '22 17:11

Yasser Shaikh


Complete code (I modified the answer provided by Yasser)

Add these code into jquery.fileupload.js

submit: function (e, data) {

    $('#fileupload').fileupload({
          formData: {
                 param1: 'test'
                ,param2: "value2"
                ,param3: "yasseshaikh"
          }
    });
},
like image 40
cp100 Avatar answered Nov 05 '22 17:11

cp100