When I created a File in SpringBoot (I can get File with data in my desktop) I am tryied send this File to Angular2 but When my File arrive , I get NULL in Angular2.
SpringBoot:
Here, I call to SpringBOOT for download Excell.
@RequestMapping(method = RequestMethod.GET, path = "/{download}", produces = MediaType.APPLICATION_JSON_VALUE)
public MultipartFile download() {
MultipartFile myFile = null;
myFile = downloadExcell();
return myFile;
}
In this function I created myExcell ,My excell is created success, I can get file in my desktop.
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++;
}
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
workbook.close();
} catch (Exception ex) {
System.out.println(ex);
}
return myFile;
}
Now I have that to assign fileOut to myFile
myFile = (MultipartFile) fileOut;
Error ->
java.lang.ClassCastException: java.io.FileOutputStream cannot be cast to org.springframework.web.multipart.MultipartFile
Finally I get (false) in Angular2 myFile.
Angular2->
downloadFile() {
this.service.downloadFile().subscribe(data => {
console.log("FILE", data);
});
}
downloadFile() {
const url = "http://localhost:8080/ml/download";
return this.http.get(url);
}
I need send the Excell the SpringBoot to Angular2, but I don't found how do. Ty