Resume upload after browser crashed

3.7k Views Asked by At

i'm working on a file upload to upload large files up to 2GB. Therefore i need to make sure that the download resumes even after the browser crashed or something. resumable.js looked very promising to me, so i gave it try:

<a href="#" id="browseButton">Select files</a>
    <!-- JAVASCRIPT -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="js/resumable.js"></script>
    <script>
        var r = new Resumable({
            target: "upload.php"
        });

        r.assignBrowse(document.getElementById("browseButton"));

        r.on('fileAdded', function(data) {
            // File added, start uploading
            r.upload();
        });

        r.on('fileProgress', function(data) {
            console.log(Math.floor(r.progress()*100) + '%');
        });
    </script>

For my upload.php (which creates a file out of the chunks) i used this php backend example: https://github.com/23/resumable.js/blob/master/samples/Backend%20on%20PHP.md

The upload works just fine, even large files, but i can't find anything useful to resume a download if i accidently closed the open tab or my browser. The php backend script seems to have implemented something to make this work:

//check if request is GET and the requested chunk exists or not. this makes testChunks work
if ($_SERVER['REQUEST_METHOD'] === 'GET') {

    $temp_dir = 'temp/'.$_GET['resumableIdentifier'];
    $chunk_file = $temp_dir.'/'.$_GET['resumableFilename'].'.part'.$_GET['resumableChunkNumber'];
    if (file_exists($chunk_file)) {
         header("HTTP/1.0 200 Ok");
       } else
       {
         header("HTTP/1.0 404 Not Found");
       }
    }

And the Resumable.js documentation says:

This will allow uploads to be resumed after browser restarts and even across browsers (in theory you could even run the same file upload across multiple tabs or different browsers). The POST data requests listed are required to use Resumable.js to receive data

But since i'm not that good at server side programming / configuration, i'm not sure how to implement that feature / check if there is an upload that can be resumed. Does anybody ran into similar problems and could explain me how to resume downloads after browser restarts?

1

There are 1 best solutions below

0
On

you can use this package

in the examples/js-examples/resumable-chunk-upload example , you can close and re-open the browser and then resume not completed uploads.