【发布时间】:2017-11-27 16:25:18
【问题描述】:
我的API如下:
@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);
休息控制器:
@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();
}
}
回应:
PK{i�Jtemp0+I�(Q(A%
问题:
我想以附件的形式下载 zip 文件,但响应如上。
注意: 我尝试了Rest Download Endpoints 上解释的所有下载方法,但都没有成功。我也加了
产生 = MediaType.APPLICATION_OCTET_STREAM_VALUE
到 API 定义,但再次没有成功。
所以,如果有人能帮助我提供真正的解决方案,我将不胜感激。
【问题讨论】:
-
我实际上已经在stackoverflow.com/questions/27952949/… 上发布了关于如何从 Spring REST 端点下载 pdf/zip 的答案。
标签: spring rest spring-boot download zip