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. WEB-INF / classes /與WEB-INF / lib / *。jar在類路徑優先級?2. javascript - js 寫一個正則 提取文本中的數據3. yii2中restful配置好后在nginx下報404錯誤4. javascript - 關于Lazyload遇到的問題5. 算法 - python 給定一個正整數a和一個包含任意個正整數的 列表 b,求所有<=a 的加法組合6. android 如何實現如圖中的鍵盤上的公式及edittext的內容展示呢7. ruby - gitlab托管,git clone 失敗?8. c++ - 如何正確的使用QWebEngineView?9. angular.js - react的redux和vue的vuex,angular呢10. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?
