我拥有一个模拟项目Maven Spring-Rest,其终点为
@RequestMapping(value = "/rest/{nid}/{fileName:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)
public String getPjSae(@PathVariable String nid, @PathVariable String fileName, HttpServletResponse response) throws IOException {
LOGGER.info("NID : " + nid);
LOGGER.info("NOM FICHIER : " + fileName);
File file = new File(saePath+File.separatorChar + fileName);
LOGGER.info("CHEMIN PJ : " + file);
if (file.exists()) {
InputStream inputStream = new FileInputStream(file); //load the file
// here I use Commons IO API to copy this file to the response output stream, I don't know which API you use.
IOUtils.copy(inputStream, response.getOutputStream());
// here we define the content of this file to tell the browser how to handle it
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".pdf");
response.flushBuffer();
}
return response.getOutputStream().toString();
}
我得到了下载的文件,并将其转换为base64以将其写入XML文件。我稍后必须进行比较,问题是在基数为64的字节流中写入对象的签名:CoyoteOutputStream
在pdf的每个base64的结尾,我都有一块:
CnN0YXJ0eHJlZgo0NjkyOAolJUVPRgpvcmcuYXBhY2hlLmNhdGFsaW5hLmNvbm5lY3Rvci5Db3lvdGVPdXRwdXRTdHJlYW1ANDA4YTViYzI=
每次都不同,因为:
startxref
46928
%% EOF
org.apache.catalina.connector.CoyoteOutputStream@408a5bc2
所以,这个坑但是比较,因为:@ 408a5bc2是唯一的
最佳答案
您最终将返回以下内容:
return response.getOutputStream().toString();
这将为相关输出流返回默认的
toString
输出,即您的CoyoteOutputStream对象签名。如果您想避免这种情况,请不要退货。关于java - 避免在Spring Rest文件下载调用中使用CoyoteOutputStream对象签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55916887/