将文件发送为缓冲区
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);
为什么不下载文件? 尝试从JSReport下载某些内容,但是如果我记录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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如 aneesh ,返回缓冲区是理想的,
您也可以使用
buffer.from()功能。
我希望它能有所帮助!
As suggested by Aneesh, returning a buffer would be ideal
You could also use the
Buffer.from()
function instead.I hope it helped!