【发布时间】:2021-11-27 09:50:00
【问题描述】:
如何转发从axios获取的文件流返回给前端?
在nest中,我正在使用axios从某处获取内容类型:“application / octet-stream”文件流,我可以获取此文件,但是如何将此文件返回到前端?
【问题讨论】:
标签: nestjs
如何转发从axios获取的文件流返回给前端?
在nest中,我正在使用axios从某处获取内容类型:“application / octet-stream”文件流,我可以获取此文件,但是如何将此文件返回到前端?
【问题讨论】:
标签: nestjs
// service
this.httpService.get(`...`, {
params: {
...
},
responseType: 'arraybuffer'
});
// controller
async export(@Req() req: any, @Res() res) {
res.header('Content-disposition', 'attachment; filename=xxx.xlsx');
res.header('Content-type', 'application/octet-stream');
const _buffer = await this.Service.export(id);
return await res.send(_buffer.data);
}
【讨论】: