文件流的处理

 // 数据流处理
    let blobType = switchType(fileFmt);
    const blob = new Blob([result.data],{
        type: blobType
     });
     let blobURL= window.URL.createObjectURL(blob);
     window.open(blobURL,'_blank');


//判断类型的方法
function switchType(fileFmt) {
   let blobType = '';
     
   switch (fileFmt) {
      case "html":
        blobType = "text/html";
      break;
      case "docx":
        blobType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
      break;
      case "doc":
        blobType = "application/msword";
      break;
     case "pdf":
       blobType = "application/pdf";
      break;
    case "jpg":
       blobType = "image/jpeg";
      break;
    case "png":
        blobType = "image/png";
      break;
    case "xlsx":
     blobType ="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      break;
    case "txt":
      blobType = "text/plain;charset=utf-8";
    break;
  }
  return blobType;
}
 

 

posted @ 2024-06-06 10:19  star-meteor  阅读(3)  评论(0编辑  收藏  举报