Send SpringBoot Excell to Angular2

0

I have created an excell in SpringBoot correctly (I can see it on the desktop) and I have to send it to Angular2, the problem is that it gives me errors when assigning the created file to the one I have to send.

@RequestMapping(method = RequestMethod.GET, path = "/{download}", produces = MediaType.APPLICATION_JSON_VALUE)
    public MultipartFile download() {

        MultipartFile myFile = null;
        myFile = downloadExcell();

        return myFile;
    }

Here the server receives the request.

private MultipartFile downloadExcell () {         MultipartFile myFile = null;         String eyelash="People";

    try {
        String filename = pathTempdownloadFile;

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet(eyelash);

        String [] header= {"YEAR","MONTH","NAME","SURNAME","TLF"} ;
        HSSFRow rowhead = sheet.createRow((short) 0);


        for (int i = 0; i < header.length; i++) {
            cell = rowhead.createCell(cellnum);
            cell.setCellValue(header[i]);
            cellnum++;
            }

         // myFile = (MultipartFile) fileOut;

        FileOutputStream fileOut = new FileOutputStream(filename);
        workbook.write(fileOut);
        fileOut.close();
        workbook.close();

    } catch (Exception ex) {
        System.out.println(ex);
    }

    return myFile;
}

Now I create the excell (it is created) and I try to assign it to the variable that I have to send to the client, but I get an error.

java.lang.ClassCastException: java.io.FileOutputStream cannot be cast to org.springframework.web.multipart.MultipartFile

I used the multiplataform because when I received the files, I used that class, so I assumed it would be the same to send the files ....

Finally, in Angular, you would receive the file:

 downloadFile() {
    this.service.downloadFile().subscribe(data => {
      console.log("FILE", data);
    });
  }

 downloadFile() {
     const url = "http://localhost:8080/ml/download";
     return this.http.get(url);
  }

Thank you.

    
asked by EduBw 19.07.2018 в 10:14
source

0 answers