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. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?2. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)3. node.js - 為什么微信的消息MsgId出現(xiàn)重復(fù)了,無(wú)法排重了。。4. mysql的主從復(fù)制、讀寫分離,關(guān)于從的問(wèn)題5. MySQL 截短某一列的字符串6. 請(qǐng)教使用PDO連接MSSQL數(shù)據(jù)庫(kù)插入是亂碼問(wèn)題?7. mysql - 分庫(kù)分表、分區(qū)、讀寫分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來(lái)哪些效率或者其他方面的好處8. mysql - 字符串根據(jù)字典替換9. 視頻文件不能播放,怎么辦?10. node.js - nodejs開(kāi)發(fā)中常用的連接mysql的庫(kù)
