The downloaded docx file is not recognized. The downloaded file name turns into an underscore and a docx underline.
The downloaded docx file is not recognized, and the downloaded file name becomes an underscore /**
* Directly use the download file page
*/
@ RequestMapping ("/download ")
@ RequiresPermissions ("sys: oss: all ")
Public void download (String id, HttpServletResponse response, HttpServletRequest request) throws Exception {
SysOssEntity ossEntity = new SysOssEntity ();
OssEntity = sysOssService. queryObject (Long. valueOf (id ));
String fileName = URLDecoder. decode (ossEntity. getDocName (), "UTF-8 ");
String path = ossEntity. getUrl ();
File file = new File (path + File. separator + fileName );
If (file. exists ()){
Response. setContentType ("multipart/form-data ");
// 2 different browsers determine the Encoding
If (request. getHeader ("User-Agent"). toUpperCase (). indexOf ("MSIE")> 0 ){
Response. setHeader ("Content-Disposition", "attachment;" + "filename =" + new
String (fileName. getBytes ("GBK"), "ISO8859-1 "));
} Else {// firefox, chrome, safari, and opera
Response. setHeader ("Content-Disposition", "attachment;" +
"Filename =" + new String (fileName. getBytes ("UTF8"), "ISO8859-1 "));
}
// IOUtils. write (data, response. getOutputStream ());
Byte [] buff = new byte [1024];
BufferedInputStream bis = null;
OutputStream OS = null;
Try {
OS = response. getOutputStream ();
Bis = new BufferedInputStream (new FileInputStream (file ));
Int I = bis. read (buff );
While (I! =-1 ){
OS. write (buff, 0, buff. length );
OS. flush ();
I = bis. read (buff );
}
} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Finally {
If (bis! = Null ){
Try {
Bis. close ();
} Catch (IOException e ){
E. printStackTrace ();
}
}
}
}