1

I am using bootstrap-fileinput, I am able to upload the file successfully, But I also want to send some data like user details with file to the server. is there any option to add data?

My JavaScript Code:

$('#xlf').fileinput({
                showPreview: false,
                uploadUrl: 'MuUrl',
                allowedFileExtensions: ['csv'],
                browseClass: "btn btn-info",
                elErrorContainer: '#errorBlock',
                msgUploadEnd: "File Uploded Successfully",
                maxFileSize: 92160
            });
ansh
  • 573
  • 3
  • 9
  • 26

1 Answers1

2

Uploading additional data to the server is done with the uploadExtraData. This only works for asynchronous uploads. If you're uploading with form submission just add the additional data in hidden fields in your form to send to your server.

Ajax submission

Here is the Asynch option.

     $('#xlf').fileinput({
            showPreview: false,
            uploadUrl: 'MuUrl',
            allowedFileExtensions: ['csv'],
            browseClass: "btn btn-info",
            elErrorContainer: '#errorBlock',
            msgUploadEnd: "File Uploded Successfully",
            maxFileSize: 92160,
            // this is where the magic happens
            uploadAsync: true,
            uploadExtraData:{
               userid:'12345',
               firstname:'Jesus',
               lastname:'Christ'
            },
        });

Hope that will help someone, even though the answer is soo super-late.

Edwin Krause
  • 1,766
  • 1
  • 16
  • 33