node.js - nodejs如何發(fā)送請(qǐng)求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. }});
相關(guān)文章:
1. nignx - docker內(nèi)nginx 80端口被占用2. docker不顯示端口映射呢?3. docker綁定了nginx端口 外部訪問不到4. angular.js - angular內(nèi)容過長展開收起效果5. javascript - nodejs調(diào)用qiniu的第三方資源抓取,返回401 bad token,為什么6. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?7. dockerfile - 我用docker build的時(shí)候出現(xiàn)下邊問題 麻煩幫我看一下8. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?9. java - 為什么此私有靜態(tài)變量能被訪問呢?10. thinkphp5.1學(xué)習(xí)時(shí)遇到session問題
