I'm actually stuck with a problem of file download from my nodeJs server. I spent many times on other topics, without any success...
I have an app on the client that propose to download some text file. So I put this code for download process:
'click .downloadF': function(event) {
var $target = $(event.target);
var file = $target.model();
var download = $.get('/files/download'+'?'+Math.random(),
{id:file.id});
},
Up to here...very simple. On my nodeJS side I made that:
app.get('/files/download', function(req, res) {
var filePath = metrology.DownloadFile(req.query.id);
var filename = path.basename(filePath);
var mimetype = mime.lookup(filePath);
res.setHeader("Content-disposition", "attachment; filename=Metrology.csv");
res.setHeader('Content-type', mimetype);
var filestream = fs.createReadStream(filePath);
filestream.pipe(res);
});
In the Response I get the right text data and the header is correctly set to attachement and file type. Response :
Connection keep-alive Content-Disposition attachment; filename=Metrology.csv Content-Type text/csv Date Mon, 16 Jun 2014 15:17:25 GMT Transfer-Encoding chunked X-Powered-By Express
Content:
NoPiece;NoRepetition;Mesure;Resultat; 1;1;1;3; 1;1;2;2; 1;1;3;2; 1;1;4;2; 2;1;1;2; 2;1;2;2; 2;1;3;2; 2;1;4;2;
Now... how can I open a dialog window to save these data into a specified filepath ???
I'm actually debuging on Mozilla, but have to work with IE9/11 too.
Many thanks for help, ideas, suggestions and (maybe) solutions :-)