Here is my backend :
public ResponseEntity getTestByURL(String filename) throws IOException {
File myExport = new File(location + filename);
HttpHeaders header = new HttpHeaders();
header.add("Content-disposition", "attachment; filename=" + filename);
String absolutePath = myExport.getAbsolutePath();
InputStreamResource resource = new InputStreamResource(new FileInputStream(absolutePath));
return ResponseEntity.ok()
.headers(header)
.contentLength(myExport.length())
.contentType(MediaType.parseMediaType("application/pdf"))
.body(resource);
}
@RequestMapping(value = "/url/{url}", produces = MediaType.APPLICATION_PDF_VALUE, method = GET)
public ResponseEntity<InputStreamResource> getTestByURL(@PathVariable(value = "url") String url) throws IOException {
return testService.getTestByURL(url);
}
And frontend :
getPDF(url: string): Observable<HttpResponse<Blob>> {
return this.http.get<HttpResponse<Blob>>(`${this.urlPDF}` + '/' + url, {
headers: new HttpHeaders({
'Content-Type': 'application/pdf',
responseType : 'blob',
Accept : 'application/pdf',
observe : 'response'
})
});
}
Give me an error, HttpErrorResponse status: 200. "Http faillure during parsing ..." "Unexpected token % in JSON at position 0 at JSON.parse"