javascript - Express res.download() and Ajax `POST` -
i using expressjs res.download()
(http://expressjs.com/en/api.html)
to send .exe
installer file. don't know if need use blob
or file
javascript apis?
i triggering call via post
action in ajax:
$('#download-form').validate({ submithandler: function (form) { $.ajax({ type: $(form).attr('method'), url: $(form).attr('action'), data: $(form).serialize(), success: function (data) { // alert(data); }, progress: function(e){ //make sure can compute length if(e.lengthcomputable) { //calculate percentage loaded var pct = (e.loaded / e.total) * 100; //log percentage loaded console.log(pct); } //this happens when content-length isn't set else { console.warn('content length not reported!'); } } }); } });
as i'm 'requesting' file in javascript, , appropriate progress
notifications, display 'ajax' loader (rather traditional download).
i've seen suggestions of "opening" response new page in "hidden iframe", or using browser api. i'm fine - haven't found example.
i interested in building downloader similar have seen on https://mega.nz/, when file downloading ajax progress bar displayed, and then user prompted save file when download complete?
Comments
Post a Comment