node.js - nodejs如何发送请求excel文件并下载
问题描述
问题解答
回答1:res.download(path [, filename] [, fn]) http://expressjs.com/en/api.h...Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download. By default, the Content-Disposition header “filename=” parameter is path (this typically appears in the browser dialog). Override this default with the filename parameter.
When an error ocurrs or transfer is complete, the method calls the optional callback function fn. This method uses res.sendFile() to transfer the file.
res.download(’/report-12345.pdf’);res.download(’/report-12345.pdf’, ’report.pdf’);res.download(’/report-12345.pdf’, ’report.pdf’, function(err){ if (err) { // Handle error, but keep in mind the response may be partially-sent // so check res.headersSent } else { // decrement a download credit, etc. }});
相关文章:
1. javascript - Vue启动时弹出错误 Failed to compile with 1 errors2. mysql 字段索引的问题3. 静态资源文件引入无效4. javascript - 怎么才能有效的防止网页被盗?5. javascript - 可以直接用node写后台接口,实现前后端分离吗?这样做合适吗?6. javascript - UI样式计算过多导致浏览器加载过慢,IE尤其严重,求前辈指导7. javascript - jQuery 获取表格所有数据8. javascript - webpack 多入口文件生成HTML文件;9. javascript - htaccess rewrite 的问题10. javascript - hammer.js panend 怎么区分是panleft 结束还是panright结束的?

网公网安备