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 sql where id in(25,12,87) 结果集如何用按照 25 12 87排序?2. 网页爬虫 - python爬虫用BeautifulSoup爬取<s>元素并写入字典,但某些div下没有这一元素,导致自动写入下一条,如何解决?3. css - 这些字体是怎么弄的?4. angular.js使用$resource服务把数据存入mongodb的问题。5. mysql中datetime列如何做筛选?6. javascript - chart.js如何修改某个指定bar的颜色7. windows-7 - Win7中Vmware Workstatoin与Xampp中Apache服务器端口冲突?8. mysql - SQL添加记录的数据来源于同一个表9. javascript - 图片请求失败怎么去掉左上角的小图标?10. javascript - vue中input的blur影响了下拉的点击事件如何解决

网公网安备