laravel download file from storage with progress bar

Solutions on MaxInterview for laravel download file from storage with progress bar by the best coders in the world

showing results for - "laravel download file from storage with progress bar"
Gareth
28 Apr 2020
1 <script type="text/javascript">
2    $(".download").click(function(){
3    window.location.href = 'file/30mb.pdf'; //set your file url which want to download
4    var data = [];
5    for (var i = 0; i < 100000; i++) {
6    var tmp = [];
7    for (var i = 0; i < 100000; i++) {
8    tmp[i] = 'hue';
9    }
10    data[i] = tmp;
11    };
12    $.ajax({
13    xhr: function () {
14    var xhr = new window.XMLHttpRequest();
15    xhr.upload.addEventListener("progress", function (evt) {
16    if (evt.lengthComputable) {
17    var percentComplete = evt.loaded / evt.total;
18    //console.log(percentComplete);
19    $('.progress').css({
20    width: percentComplete * 100 + '%'
21    });
22    if (percentComplete === 1) {
23    $('.progress').addClass('hide');
24    }
25    }
26    }, false);
27    xhr.addEventListener("progress", function (evt) {
28    if (evt.lengthComputable) {
29    var percentComplete = evt.loaded / evt.total;
30    console.log(Math.round(percentComplete*100)+"%");
31    $(".perc").text(Math.round(percentComplete*100)+"%");
32    if((Math.round(percentComplete*100))==100)
33    {
34    $(".perc").text("download completed");
35    $('.progress').removeClass('hide');
36    // $(".perc").text("");
37    }
38    $('.progress').css({
39    width: percentComplete * 100 + '%'
40    });
41    }
42    }, false);
43    return xhr;
44    },
45    type: 'POST',
46    url: "file/30mb.pdf", //set your file url which want to download
47    data: data,
48    success: function (data) {}
49    });
50    });
51
52    </script>