springboot解决下载文件,文件名中文乱码问题

更新时间:2023-06-14 17:01:59 阅读: 评论:0

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;
}
}

本文发布于:2023-06-14 17:01:59,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/953918.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:计划   景色   解决   问题
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图