最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
下載文件流文件名轉(zhuǎn)碼-創(chuàng)新互聯(lián)

下載文件,后端返回文件流,前端下載并讀取后端返回文件名content-disposition

成都創(chuàng)新互聯(lián)專業(yè)IDC數(shù)據(jù)服務器托管提供商,專業(yè)提供成都服務器托管,服務器租用,西部信息機房,西部信息機房,成都多線服務器托管等服務器托管服務。

后端接口返回content-disposition:

前端讀取文件名并下載

1.axios返回請求響應全部數(shù)據(jù)

service.interceptors.response.use((response: AxiosResponse) =>{
  const result = response.data;
  const { config: { responseType } } = response;
  if (responseType === 'blob') {
    return response;
  }

2.接口調(diào)用返回中讀取解碼:decodeURI(fileName)

getExport().then((res:any) =>{
          const fileName = res.headers['content-disposition'].split(';')[1].split('filename=')[1];
// 轉(zhuǎn)換編譯content-disposition的文件名:decodeURI
          downloadFile(decodeURI(fileName), res.data);
        });

3.文檔流下載方法

export function downloadFile(fileName:string, content:Blob, unicode = 'application/octet-stream;charset=utf-8'):void {
  // const blob = new Blob([content], { type: unicode });
  if ('download' in document.createElement('a')) { // 非IE下載
    const downloadElement = document.createElement('a');
    let href = '';
    if (window.URL) {
      href = window.URL.createObjectURL(content);
    } else {
      href = window.webkitURL.createObjectURL(content);
    }
    downloadElement.href = href;
    downloadElement.download = fileName;
    document.body.appendChild(downloadElement);
    downloadElement.click();
    if (window.URL) {
      window.URL.revokeObjectURL(href);
    } else {
      window.webkitURL.revokeObjectURL(href);
    }
    document.body.removeChild(downloadElement);
  }

你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧


分享文章:下載文件流文件名轉(zhuǎn)碼-創(chuàng)新互聯(lián)
文章位置:http://fisionsoft.com.cn/article/geijd.html