Jquery File Upload invoking upload handler on load

I am using jQuery File Upload (https://github.com/blueimp/jQuery-File-Upload). I am using Terascript for my server side upload handler and it seems to work fine.

But unfortunately jQuery File Upload seems to want to invoke the upload handler on load, before you have told it what files you want to upload and manually triggered the upload. The upload handler creates an random name but of course there is no actual file associated with it.

http://dev.over60travel.com/sandbox/jquery-file-uploads/index.html

Afterwards it all seems to work fine. But why does it trigger an upload on load?

728x90

2 Answers Jquery File Upload invoking upload handler on load

Thank you to Sebastian Tschan, the author of jQuery-File-Upload, for the answer to this question.

On load the app does indeed call the upload module. I'm still not entirely sure why but the way to stop it is to comment out the follwoing lines from 'main.js'.

        // Load existing files:
//    $('#fileupload').addClass('fileupload-processing');
//    $.ajax({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
//        url: $('#fileupload').fileupload('option', 'url'),
//        dataType: 'json',
//        context: $('#fileupload')[0]
//    }).always(function () {
//        $(this).removeClass('fileupload-processing');
//    }).done(function (result) {
//        $(this).fileupload('option', 'done')
//            .call(this, $.Event('done'), {result: result});
//    });

5 months ago

It dawned on me on Friday evening that this is actually a file management (rather than upload) interface. On load you are requesting a list of existing files and that is the process that was causing my issue. Sorry for being a bit slow. ;)

I had changed my upload handler so that if it is called without a file argument it returned nothing. That was my original cure. Then Sebastian suggested removal of the code that requests it onload and that was a better solution. Now that I understand why it is called onload I thought I would have a try at getting it working as initially intended.

I have uncommented the code and changed my upload handler so that if no file argument is sent, it returns JSON in the format specified in the documentation. Awesome!

5 months ago