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優化 - 關于mysql分區2. php laravel框架模型作用域3. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?4. java - Atom中文問題5. java - MySQL中,使用聚合函數+for update會鎖表嗎?6. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應7. javascript - ionic2 input autofocus 電腦成功,iOS手機鍵盤不彈出8. html5 - 如何實現帶陰影的不規則容器?9. vue.js - vue 打包后 nginx 服務端API請求跨域問題無法解決。10. javascript - 為什么這個點擊事件需要點擊兩次才有效果
