Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery-File-Upload by blueimp - additional headers

I've searched through wiki but couldn't find an answer where should I put my additional headers (for example Authorization header) in JS script? Somewhere onSend/beforeSend or?

Widget link: https://github.com/blueimp/jQuery-File-Upload

like image 323
svenkapudija Avatar asked Apr 04 '12 13:04

svenkapudija


2 Answers

This is how I added the filename as a header:

$('#upload_btn').fileupload({
    singleFileUploads: true,
    beforeSend: function(xhr, data) {
        var file = data.files[0];
        xhr.setRequestHeader('X-FileName', file.name);
    },
});
like image 143
mpen Avatar answered Oct 27 '22 01:10

mpen


Did you try to set additional headers through "options.headers" object?

If using the forceIframeTransport: true option (with IE not supporting XHR file uploads you need to fall back on the hidden iframe approach), then modifying headers is not an option: https://github.com/blueimp/jQuery-File-Upload/issues/654

Options.headers: http://api.jquery.com/jQuery.ajax/

The options set for the File Upload plugin are passed to jQuery.ajax() and allow to define any ajax settings or callbacks.

like image 22
dgrubelic Avatar answered Oct 27 '22 02:10

dgrubelic