Monday, 6 May 2019

How to upload files via ajax without timeouts?

I'm using ajax to upload a group of ~50 files, all <= 5MB. If the connection is on the slower side, the upload will "timeout" without even finishing the first upload (approx ~45 seconds into upload).

In Firefox, ajax will fail with an 'error' response but no further info. In Chrome, I get an net::ERR_CONNECTION_RESET error.

I've checked my Apache and php.ini settings, and I believe they are all sufficient.

post_max_size = 1000M
upload_max_filesize = 15M
max_input_time = -1
max_execution_time = 0
max_file_uploads = 50
memory_limit = 128M

I've also tried setting ajax's timeout parameter to 0. My ajax request looks sort of like this:

return $.ajax({ 
    url: ajaxpath,
    type: 'post',
    data: formData,
    dataType: 'json',
    timeout: 0,
    xhr: function(){

        var myXhr = $.ajaxSettings.xhr();

        if(myXhr.upload) myXhr.upload.addEventListener('progress',function(e){

            uploadProgress(e,item);

        },false);

        return myXhr;

    },
    processData: false,
    contentType: false

}).fail(function(jqXHR,textStatus,errorThrown){

            console.log(textStatus,errorThrown);

        });

    }

With quicker connections, I don't seem to get this problem. If I use my browser's developer tools to throttle the speed, it'll happen, which is what I'm doing to replicate my users' situation.

Am I missing a setting somewhere? How can I keep the upload alive?



from How to upload files via ajax without timeouts?

No comments:

Post a Comment