I am trying to download a DMN File, which is basically a XML File, which I get from Spring Boot Backend. I am sure that the backend works, because the HTTP Request is succesful and I get some byte Array as response from backend, and also if I try with Postman, I get the right file and content.
But if try to open the file in my Angular App, the file just contains [object Object] as content.
Here is my code:
Backend:
@GetMapping(path = "/dmn-definition/{dmnId}/download")
public ResponseEntity<byte[]> downloadDMNById(@ApiParam(required = true) @PathVariable String dmnId) {
String xml = IoUtil.inputStreamAsString(repositoryService
.getDecisionModel(dmnId));
HttpHeaders headers = new HttpHeaders();
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + dmnId + ".dmn");
byte[] content = xml.getBytes();
return ResponseEntity.ok()
.headers(headers)
.contentLength(content.length)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(content);
}
Frontend:
downloadDmnFileById(id: string): Observable<ArrayBuffer> {
const httpOptions : Object = {
headers: new HttpHeaders({
'Accept': 'application/octet-stream',
}),
responseType: 'blob',
observe: 'response'
};
return this.httpClient.get<ArrayBuffer>(`${baseUrl}/dmn-definition/${id}/download`, httpOptions);
}
onDownloadDmnFile(dmn: Dmn): void {
this.dmnService
.downloadDmnFileById(dmn.id, this.processGroupName)
.subscribe((result) => {
const a = document.createElement('a');
document.body.appendChild(a);
let binaryData = [];
binaryData.push(result);
const blob = new Blob(binaryData, { type: 'application/xml' });
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = dmn.id + ".dmn";
a.click();
window.URL.revokeObjectURL(url);
});
}