2017-09-20 18 views
6

Tôi đang tạo một ứng dụng mà tôi đang tải xuống tệp. Đối với điều này tôi nhận được phản hồi từ lớp java trong js và tải response.For này này mã java của tôi là -Tải xuống tệp trong IE11 gặp lỗi "'Uint8Array' không xác định"

@ApiOperation(value = "", 
      notes = "") 
@Path("/getProjectJSONTODRAW/{implementation}") 
@GET 
@Timed 
public Response getProjectJSONTODRAW(@PathParam("implementation") String implementation) { 
     File file = new File(path+File.separator+fileName); 
     InputStream inputStream =null; 
     String mimeType =null; 
     if (!file.exists()) { 
      String errorMessage = "Sorry. The file you are looking for does not exist"; 
      log.info(errorMessage); 
     }else { 
      mimeType = URLConnection.guessContentTypeFromName(file.getName()); 
      if (mimeType == null) { 
       log.info("mimetype is not detectable, will take default for the file "+file.getName()); 
       mimeType = "application/octet-stream"; 
      } 
      try { 
       inputStream = new BufferedInputStream(new FileInputStream(file)); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } 
     } 
     return Response 
       .ok(inputStream, mimeType) 
       .header("Content-Disposition", "attachment; filename=\""+file.getName()+"\"") 
       .header("Content-Length", file.length()) 
       .build(); 
} 

Và trong JS code đang -

 $http.get('/api/1/explore/getProjectJSONTODRAW/implementation', { 
         responseType: 'arraybuffer' 
        }) 
        .success(function(response) { 
         var a = document.createElement("a"); 
         document.body.appendChild(a); 
         var fileName = "abc.pdf"; 
         var mimeType = "application/pdf"; 
         var blob = new Blob([response], { 
          type: mimeType 
         }), 
         url = window.URL.createObjectURL(blob); 
         a.href = url; 
         a.download = fileName; 
         var isIE = false || !!document.documentMode; 
         if (isIE) { 
          a.style.cssText = "display: none;" 
          window.navigator.msSaveOrOpenBlob(blob, fileName); 
         } else { 
          a.style = "display: none"; 
          a.click(); 
          window.URL.revokeObjectURL(url); 
         } 
        }).catch(function(error) { 
         console.log(error); 
        }); 
} 

này cho tôi lỗi tại

var blob = Blob mới ([phản ứng], {type: mIMETYPE})

Lỗi là - " 'Uint8Array' là undefined" và phiên bản trình duyệt IE của tôi là - IE11

+0

'Uint8Array' được liệt kê như quy định tại IE10 + https: //developer.mozilla .org/en-US/docs/Web/JavaScript/Tham chiếu/Global_Objects/Uint8Array. Có lỗi nào khác được ghi lại không? – guest271314

Trả lời

3

phiên bản góc của tôi là 1.2.26 và Uint8Array được hỗ trợ trong phiên bản sau của góc 1,5 và thêm

<meta http-equiv="X-UA-Compatible" content="IE=11" /> 
0

Nếu Blob không ném một lỗi mà bạn có thể sử dụng responseType: "blob".

Các vấn đề liên quan