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. mysql - 在不允许改动数据表的情况下,如何优化以varchar格式存储的时间的比较?2. css - chrome下a标签嵌套img 显示会多个小箭头?3. docker网络端口映射,没有方便点的操作方法么?4. javascript - 网页打印页另存为pdf的代码一个问题5. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.6. css3 - 纯css实现点击特效7. java中返回一个对象,和输出对像的值,意义在哪儿8. javascript - 有适合开发手机端Html5网页小游戏的前端框架吗?9. javascript - Img.complete和img.onload判断图片加载完成有什么区别?10. mysql 为什么主键 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?
