Utilizing Polymer's iron-ajax element, I am making an XMLHTTPRequest to a server endpoint:
<iron-ajax
id="ajax"
method="POST"
url="/export/"
params=''
handle-as="json"
on-response="handleResponse"
</iron-ajax>
The response from my Koa/Express-server includes a read stream as shown below:
router.post('/export', function*(){
var file = __dirname + '/test.zip';
var filename = path.basename(file);
var mimetype = mime.lookup(file);
this.set('Content-disposition', 'attachment; filename=' + filename);
this.set('Content-type', mimetype);
this.body = fs.createReadStream(file);
})
In the function handleResponse()
, how can I trigger the download without directly handling the response?
Preferably, I would like to initiate the download without any intermediary steps.
The expected response headers are as follows:
Content-disposition: attachment; filename=test.zip
Connection: keep-alive
Transfer-Encoding: chunked
Content-type: application/zip