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. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?2. mysql優(yōu)化 - 關(guān)于mysql分區(qū)3. html5 - 如何實(shí)現(xiàn)帶陰影的不規(guī)則容器?4. javascript - 循環(huán)嵌套多個(gè)promise應(yīng)該如何實(shí)現(xiàn)?5. python - 管道符和ssh傳文件6. 請(qǐng)教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒(méi)有反應(yīng)7. objective-c - iOS開(kāi)發(fā)支付寶和微信支付完成為什么跳轉(zhuǎn)到了之前開(kāi)發(fā)的一個(gè)app?8. javascript - 為什么這個(gè)點(diǎn)擊事件需要點(diǎn)擊兩次才有效果9. javascript - ionic2 input autofocus 電腦成功,iOS手機(jī)鍵盤(pán)不彈出10. vue.js - vue 打包后 nginx 服務(wù)端API請(qǐng)求跨域問(wèn)題無(wú)法解決。
