Browse Source

图片转换成base64码进行显示

tags/v1.1.0
qiujinyang 2 years ago
parent
commit
51c35d4cd5
1 changed files with 12 additions and 11 deletions
  1. +12
    -11
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java

+ 12
- 11
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java View File

@@ -503,16 +503,17 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
log.info("问题清单写入完成");

//清空缓存
response.reset();
// 定义浏览器响应表头,并定义下载名
//String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8");
String urlFileName =new String(("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc").getBytes(), StandardCharsets.ISO_8859_1);
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName);
response.setCharacterEncoding("utf-8");
//定义下载的类型
response.setContentType("application/msword;charset=utf-8");
OutputStream out;
File files = new File(filePath);
response.reset();
// 定义浏览器响应表头,并定义下载名
//String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8");
String urlFileName =new String(("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc").getBytes(), StandardCharsets.ISO_8859_1);
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName);
response.setCharacterEncoding("utf-8");
//定义下载的类型
response.setContentType("application/octet-stream;charset=utf-8");

OutputStream out;
//File files = new File(filePath);

log.info("读出的文件文件地址为:{}",filePath);
InputStream inputStream = this.getClass().getResourceAsStream(filePath);
@@ -520,7 +521,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
//3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[512];
byte[] buffer = new byte[1024];
while (b != -1){
b = inputStream.read(buffer);
//4.写到输出流(out)中

Loading…
Cancel
Save