node.js - nodejs如何發(fā)送請(qǐng)求excel文件并下載
問(wèn)題描述
問(wèn)題解答
回答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. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒(méi)有內(nèi)容的不占據(jù)位置嗎;2. python - Fiddler+Android模擬器抓取app,json數(shù)據(jù)被加密了,如何解析?3. thinkPHP5中獲取數(shù)據(jù)庫(kù)數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見(jiàn)。有圖有代碼,希望有人幫忙4. java - 如何用圖畫(huà)的方式有效地表示多線程?5. wordpress里,這樣的目錄列表是屬于小工具還是啥?6. MySQL 使用 group by 之后然后 IFNULL(COUNT(*),0) 為什么還是會(huì)獲得 null7. 百度地圖 - Android app中準(zhǔn)備接入地圖sdk,百度VS高德哪個(gè)好一點(diǎn)?8. python 3.4 error: Microsoft Visual C++ 10.0 is required9. 我的怎么不顯示啊,話說(shuō)有沒(méi)有QQ群什么的10. 常量在外面不加引號(hào)會(huì)報(bào)錯(cuò)。
