problem description
the picture request is successful, and the picture is displayed normally, but an error is reported in the background.
Page picture request
@RequestMapping("/see/{id}")
public void seeUrl(@PathVariable("id")Integer id) {
sysFileService.fileDownload(id, false, true, response);
}
@Override
public void fileDownload(Integer id, Boolean isName, Boolean isOpen, HttpServletResponse response) {
TbFile tbFile = tbFileMapper.selectByPrimaryKey(id);
if( null != tbFile) {
File file = new File(tbFile.getSaveDir() + "/" + tbFile.getSaveName() + "." + tbFile.getFileSuffix());
if(file.exists()){
try {
FileUtils.fileDownload(file, tbFile, response, isName, isOpen);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void fileDownload(File file, TbFile tbFile, HttpServletResponse response, Boolean isName, Boolean isOpen) throws FileNotFoundException, IOException {
String fullName = "";
//
if(null == isName) {
fullName = new String(tbFile.getFileName().getBytes(),"ISO-8859-1") + "."+tbFile.getFileSuffix();
} else {
fullName = new String(tbFile.getSaveName().getBytes(),"ISO-8859-1") + "."+tbFile.getFileSuffix();
}
//
if(null == isOpen) {
//
response.setContentType("application/force-download");
response.setHeader("Content-Disposition", "attachment;fileName=" + fullName);
}else {
//
response.setContentType(tbFile.getFileType());
response.setHeader("Content-Disposition", "inline;fileName=" + fullName);
}
streamWrite(new FileInputStream(file), response.getOutputStream());
logger.info(
"fileDownload---" +
"\t:" + tbFile.getFileName() +
"\t:" + tbFile.getFileType() +
"\t:" + tbFile.getFileSize() +
"\t:" + tbFile.getSaveDir() +
"\t:" + tbFile.getSaveName()
);
}
public static void streamWrite(InputStream is, OutputStream os) throws IOException {
byte[] b = new byte[1024];
int len;
while((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
os.flush();
os.close();
is.close();
}
what result do you expect? What is the error message actually seen?
1. Does this request path still need to be configured not to access the jsp file
2. When it is still backend response, set a value and do not request again after success.