I’ve developed a REST endpoint that produces a zip file serialized to a byte array.
@GetMapping(path = "/export-zip", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<byte[]> exportZipFile() throws IOException {
try {
MyZipObject zip = zipService.createZip();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + zip.getFileName() + ".zip\"");
return new ResponseEntity<>(zip.getData(), httpHeaders, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Using Postman, I can successfully get the response from this API and save it to a Zip file. However the React code that our front-end uses to call this API is producing an error
Refused to get unsafe header “Content-Disposition"
I’m unsure why the header is considered unsafe to begin with but I’d also like to know how I can render it a safe header.