Как конвертировать Blob XML в документ в Angular2 + - PullRequest
0 голосов
/ 14 июня 2019

Я получаю ответ от серверной части (java) в формате xml успешно, и я загрузил, но когда я пытаюсь открыть его, я получаю недопустимую ошибку ввода / вывода.

// это метод из моего сервиса

getDoc(){
   return this.http.get("http://localhost:17080/files/doc",{responseType: 
'text'});
  }

// это мой метод в файле .ts

openDoc(){
    this.dataService.getDoc().subscribe((response)=>{
      console.log(response);
      let blob = new Blob([response],  { type: 
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' 
});

      fs.saveAs(blob, "name.doc");
  }

// а это метод из моего бэк-энда

@RequestMapping(value = "/doc", method = RequestMethod.GET)
    public byte[] getDoc(){ 
        return readFile("somelink");
    }

// метод readFile

private byte[] readFile(String url) {

        BufferedInputStream bis = null;

        try {
            bis = new BufferedInputStream(new URL(url).openStream());
            byte[] dataToReturn = new byte[ARRAY_SIZE];
            bis.read(dataToReturn, 0, ARRAY_SIZE);
            return dataToReturn;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            if(bis != null) {
                try {
                    bis.close();
                } catch (IOException e){
                    // TODO Auto-generated catch block
                     e.printStackTrace();
                }
            }
         }
...