我正在从控制器下载文件。这没用。这是因为文件名中的“,”。如果我从名称中删除“,”,它将起作用。是否有任何解决方法。我应该做 String.replace("," "")。肯定有更好的办法?
response.setHeader("Content-Disposition", "inline; filename=" + "abbbbababbaababba.4.1.2013,aakdfhfdf.xlsx");
完整方法
@RequestMapping(value = "/newsimage/{newsImageId} ", method = RequestMethod.GET)
public void getImage(HttpServletRequest request, HttpServletResponse response, @PathVariable long newsImageId) {
NewsImage newsImage = newsImageService.findById(newsImageId);
String fileName = newsImage.getFileName();
response.setHeader("Content-Disposition", "inline; filename=" + "abbbbababbaababba.4.1.2013,aakdfhfdf.xlsx");
response.setContentType(newsImage.getContentType());
// response.setHeader("Content-Disposition", "attachment;filename=" + newsImage.getFileName());
OutputStream out;
try {
out = response.getOutputStream();
out.write(newsImage.getData());
out.flush();
} catch (IOException e) {
logger.error(e.getMessage());
}
}