[英]How to pass value using variable in res.setHeader express.js
Trying to send file on the frontend with its name and extension.尝试在前端发送文件及其名称和扩展名。
var fileReadStream = fs.createReadStream(filePath);
res.setHeader("Content-disposition", `attachment; filename=${fileName}`);
fileReadStream.pipe(res);
On the frontend, getting ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION在前端,获取ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
How can I send the file name with its extension to download on the frontend?如何发送带有扩展名的文件名以在前端下载?
You need to set the header like this您需要像这样设置 header
Content-Disposition: attachment; filename="filename.jpg"
In your case you should do it like below在你的情况下,你应该像下面那样做
var fileReadStream = fs.createReadStream(filePath);
res.setHeader(`Content-Disposition: attachment; filename=${fileName}`);
fileReadStream.pipe(res);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.