jQuery-File-Upload by blueimp - additional headers

svenkapudija picture svenkapudija · Apr 4, 2012 · Viewed 17.4k times · Source

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

Answer

mpen picture mpen · May 7, 2013

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);
    },
});