My API is as follows:
@ApiOperation(value = "Zip of all the documents the customer attached to their application (id and loan)", notes = "", response = Void.class, tags = {
"Manage Customers/Applications",
})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = Void.class)
})
@RequestMapping(value = idPath + "/files/customer-documents/zip",
method = RequestMethod.GET)
@ResponseBody
void downloadCustomerDocumentsAsZip(HttpServletResponse response,
@ApiParam(value = "Application ID", required = true) @PathVariable(value = "applicationId")
Long applicationId);
The Rest Controller:
@Override
public void downloadCustomerDocumentsAsZip(HttpServletResponse response,
@ApiParam(value = "Application ID", required = true) @PathVariable(value = "applicationId")
Long applicationId) {
InputStream inputStream = new ByteArrayInputStream(manageApplicationsService.findCustomerDocumentsAsZip(applicationId));
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition", "attachment; filename=zipFile.zip");
try {
FileCopyUtils.copy(inputStream, response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
The Response:
PK{i�Jtemp0+I�(Q(A%
Issue:
I want to download the zip file as an attachment, but the response is as above.
Note: I tried all the download methods which are explained on Rest Download Endpoints but none of them were successful. I also add
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE
to the API definition but again no success.
So, I would be so grateful if anyone could help me with their genuine solution.