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. nignx - docker內nginx 80端口被占用2. docker不顯示端口映射呢?3. docker綁定了nginx端口 外部訪問不到4. angular.js - angular內容過長展開收起效果5. javascript - nodejs調用qiniu的第三方資源抓取,返回401 bad token,為什么6. docker網絡端口映射,沒有方便點的操作方法么?7. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下8. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?9. java - 為什么此私有靜態變量能被訪問呢?10. thinkphp5.1學習時遇到session問題
