2017-09-20 27 views
6

Tworzę aplikację, w której pobieram plik. Do tego mam odpowiedzi od klasy Java w js i pobierz to response.For to mój kod Java -Pobierz plik w IE11 "" Uint8Array "jest niezdefiniowany"

@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(); 
} 

I w JS kod jest -

 $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); 
        }); 
} 

To daje mi błąd w

var kropelka = nowy blob ([odpowiedzi] {typ: mimeType})

Błąd jest - „«Uint8Array»jest niezdefiniowana” i moja wersja IE jest - IE11

+0

'Uint8Array' znajduje się na liście, jak określono w IE10 + https: //developer.mozilla .org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array. Czy są rejestrowane inne błędy? – guest271314

Odpowiedz

3

My kątowe wersja 2.1.26 i Uint8Array jest obsługiwana w nowszej kątowego 1,5 dodać

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

Jeśli Blob nie wyrzuca błędu można użyć responseType: "blob".