Search code examples
ajaxamazon-s3restartpluploadabort

Resume or restart ajax request after network connection abort while uploading large images?


I am trying to upload large files using PLUpload library.at fileUploaded function I have ajax call to upload image to Amazon S3 but ajax call fails prompting error network connection aborted. Please help how to restart or resume my request


Solution

  • First I detected the network is down or running perfectly fine using offline js

    var run = function(){        
             Offline.check();
        }
    
        setInterval(run, 3000);
    

    check every 3 seconds network connection available or not.

    when network goes up after re-connection perform action at up function

    Offline.on('up', function(){
    if(ajax_response === null || ajax_response == 'error')
    {
        rename_file (oldname,newname)
    }
    });         
    

    store function parameters as global variables to use it for function call.

        var ajax_response = null;
    window.rename_file = function(oldname,newname)
        {
            var resp =null;
    
            $.ajax({            
                url:'ajaxcall.php',
                data:{action:'rename_file',new_name:newname,old_name:oldname},  
                async:false,            
                success:function(data,status)
                {
                    resp = 'success';
                },
                error: function(jqXHR, textStatus, errorThrown) {               
                    resp = 'error';                 
                }
            });
    
            ajax_response.= resp;
            return resp;
        }