laravel download file from storage with progress bar code example
Example: laravel download file from storage with progress bar
<script type="text/javascript">
$(".download").click(function(){
window.location.href = 'file/30mb.pdf';
var data = [];
for (var i = 0; i < 100000; i++) {
var tmp = [];
for (var i = 0; i < 100000; i++) {
tmp[i] = 'hue';
}
data[i] = tmp;
};
$.ajax({
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
$('.progress').css({
width: percentComplete * 100 + '%'
});
if (percentComplete === 1) {
$('.progress').addClass('hide');
}
}
}, false);
xhr.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
console.log(Math.round(percentComplete*100)+"%");
$(".perc").text(Math.round(percentComplete*100)+"%");
if((Math.round(percentComplete*100))==100)
{
$(".perc").text("download completed");
$('.progress').removeClass('hide');
}
$('.progress').css({
width: percentComplete * 100 + '%'
});
}
}, false);
return xhr;
},
type: 'POST',
url: "file/30mb.pdf",
data: data,
success: function (data) {}
});
});
</script>