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. java - 自己制作一個視頻播放器,遇到問題,用的是內置surfaceview類,具體看代碼!2. 服務器端 - 采用nginx做web服務器,C++開發應用程序 出現拒絕連接請求?3. javascript - vue 移動端的input 數字輸入優化4. javascript - 有什么兼容性比較好的辦法來判斷瀏覽器窗口的類型?5. 關于docker下的nginx壓力測試6. 為什么我ping不通我的docker容器呢???7. javascript - Angular controlller控制域和原生js的關系8. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe9. javascript - nidejs環境設置操作一直出現這種問題怎么解決?10. javascript - npm start 運行’webpack-dev-server’報錯 Cannot find module ’webpack’
