I'm using Koa as a webserver to serve my Polymer application. Upon pressing a button in the frontend localhost:3000/export
is called. I would like to deliver a file-download to the client after packing the some files to a zip-archive.
How to do this in Koa.js?
Here's an example on how to do it in Express (another option would be the download-helper
app.get('/export', function(req, res){
var path = require('path');
var mime = require('mime');
var file = __dirname + '/upload-folder/dramaticpenguin.MOV';
var filename = path.basename(file);
var mimetype = mime.lookup(file);
res.setHeader('Content-disposition', 'attachment; filename=' + filename);
res.setHeader('Content-type', mimetype);
var filestream = fs.createReadStream(file);
filestream.pipe(res);
});
I'm looking for something like this:
router.post('/export', function*(){
yield download(this, __dirname + '/test.zip')
})