'Send file as buffer
const resp = await client.render(data);
const Writable = require('stream').Writable;
var buffer = [];
const myWritable = new Writable({
write(chunk, encoding, callback) {
console.log(encoding);
buffer += chunk;
callback();
},
});
myWritable.on('finish', () => {
res.writeHead(200, {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition': `inline; filename=Non Billed Jobs.xlsx`,
});
res.end(buffer);
});
resp.pipe(myWritable);
Why doesn’t this download the file?
Trying to download something from jsreport but if I log buffer
, it gives me strange characters
Solution 1:[1]
As suggested by Aneesh, returning a buffer would be ideal
res.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.set('Content-Disposition', 'inline; filename=Non Billed Jobs.xlsx');
res.send(new Buffer(BUFFER_DATA, 'base64');
You could also use the Buffer.from()
function instead.
I hope it helped!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | crazy_enter |