admin管理员组文章数量:1399976
I'm using nodejs to send file streams to express response
var fileReadStream = fs.createReadStream(filePath);
fileReadStream.pipe(res);
The problem is, on the front-end, the file is downloadable only with the "download", and without extension. And this makes the file unable to use (as no extension).
I'm using nodejs to send file streams to express response
var fileReadStream = fs.createReadStream(filePath);
fileReadStream.pipe(res);
The problem is, on the front-end, the file is downloadable only with the "download", and without extension. And this makes the file unable to use (as no extension).
Share Improve this question edited Feb 17, 2022 at 16:17 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Feb 17, 2022 at 11:22 M.K. MalikM.K. Malik 1931 gold badge2 silver badges11 bronze badges 1-
2
Adding
Content-Disposition: attachment; filename="FILENAME"
header to your response should do the trick. – Daniel Commented Feb 17, 2022 at 11:34
1 Answer
Reset to default 8please add this header before sending the response(replace the filename according your need):
var fileReadStream = fs.createReadStream(filePath);
res.setHeader('Content-disposition', 'attachment; filename=YOUR_FILE.EXTENSION');
fileReadStream.pipe(res);
本文标签: javascriptHow to send file stream with file name and file extension using NodeJSStack Overflow
版权声明:本文标题:javascript - How to send file stream with file name and file extension using NodeJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744198875a2594870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论