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 - ehcache緩存用的是虛擬機內存么?2. javascript - JS如何取對稱范圍的隨機數?3. 數據庫 - mysql如何處理數據變化中的事務?4. 關于docker下的nginx壓力測試5. javascript - 有什么兼容性比較好的辦法來判斷瀏覽器窗口的類型?6. java - mongodb分片集群下,count和聚合統計問題7. android - java 泛型不支持數組,那么RxJava的Map集合有什么方便的手段可以定義獲得一串共同父類集合數據呢?8. 服務器端 - 采用nginx做web服務器,C++開發應用程序 出現拒絕連接請求?9. java - 自己制作一個視頻播放器,遇到問題,用的是內置surfaceview類,具體看代碼!10. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下
