11.前台文件数据流下载获取源文件名
生活随笔
收集整理的這篇文章主要介紹了
11.前台文件数据流下载获取源文件名
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.文件流下載文件
axios實現:
export function download(url, data){axios.post(baseurl+url,data,{responseType: 'blob'}).then(function (response) {var filename = response.headers//下載后文件名filename = filename["content-disposition"]filename = filename.split(";")[1].split("filename=")[1];var blob = new Blob([response.data])var downloadElement = document.createElement('a');var href = window.URL.createObjectURL(blob); //創建下載的鏈接downloadElement.href = href;downloadElement.download = filenamedocument.body.appendChild(downloadElement);downloadElement.click(); //點擊下載document.body.removeChild(downloadElement); //下載完成移除元素window.URL.revokeObjectURL(href); //釋放掉blob對象 }).catch(function (error) {console.log("File download error!")}) }注意,想要獲取headers中content-disposition的數據,服務端要加一個:
response.setHeader("Access-Control-Expose-Headers","Content-Disposition");轉載于:https://www.cnblogs.com/TimerHotel/p/vue_11.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的11.前台文件数据流下载获取源文件名的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux基础命令---su
- 下一篇: Spring Boot 应用程序启动流程