springboot解决下载⽂件,⽂件名中⽂乱码问题
/**
* ⽂件下载
*
* @param id
* @return
*/
@GetMapping("/downloadFile")
春天公园景色描写
@ApiOperation(value = "⽂件下载")
public void downloadFile(HttpServletRequest request,HttpServletRespon respon,@RequestParam("urId")String urId,@RequestParam("fileId")String fileId) {
byte[] buffer = new byte[1024];
try {
FileBean bean = FileInfo(urId,fileId);
String filePath = FilePath();
File file = new File(filePath);
ists()) {
InputStream in = new FileInputStream(file);
tHeader(request,Name());
OutputStream outputStream = OutputStream();
ad(buffer,0,1024) != -1){
outputStream.write(buffer, 0, buffer.length);
}
自律计划
广西三月三}
fileStoreService.updateUrFile(urId,fileId,"download");
} catch (Exception e) {
<(e.getMessage());
}
}
private boolean tHeader(HttpServletRequest request, HttpServletRespon respon, String fileName) { try {
respon.tContentType("application/octet-stream");
respon.tHeader("content-type", "application/octet-stream");
String browr = Header("Ur-Agent");
if (-1 < browr.indexOf("MSIE 6.0") || -1 < browr.indexOf("MSIE 7.0")) {
食堂用英语怎么说
平安富贵// IE6, IE7 浏览器
respon.addHeader("content-disposition", "attachment;filename="
+ new Bytes(), "ISO8859-1"));
} el if (-1 < browr.indexOf("MSIE 8.0")) {
// IE8
respon.addHeader("content-disposition", "attachment;filename="
+ de(fileName, "UTF-8"));
} el if (-1 < browr.indexOf("MSIE 9.0")) {
// IE9
respon.addHeader("content-disposition", "attachment;filename="
+ de(fileName, "UTF-8"));
} el if (-1 < browr.indexOf("Chrome")) {
// ⾕歌
机器人的英文respon.addHeader("content-disposition",
"attachment;filename*=UTF-8''" + de(fileName, "UTF-8"));
} el if (-1 < browr.indexOf("Safari")) {
关于桥的谜语// 苹果
respon.addHeader("content-disposition", "attachment;filename="
+ new Bytes(), "ISO8859-1"));
福照片} el {
// ⽕狐或者其他的浏览器
respon.addHeader("content-disposition",
"attachment;filename*=UTF-8''" + de(fileName, "UTF-8"));
}
return true;
} catch (Exception e) {
<(e.getMessage());
return fal;
}
}