Browse Source

图片转换成base64码进行显示

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

+ 7
- 3
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java View File

import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
//清空缓存 //清空缓存
response.reset(); response.reset();
// 定义浏览器响应表头,并定义下载名 // 定义浏览器响应表头,并定义下载名
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8");
//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.setHeader("Content-Disposition", "attachment;filename=" + urlFileName);
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
//定义下载的类型 //定义下载的类型
response.setContentType("application/msword;charset=gbk");
response.setContentType("application/msword;charset=utf-8");
OutputStream out; OutputStream out;
File files = new File(filePath); File files = new File(filePath);


log.info("读出的文件文件地址为:{}",filePath); log.info("读出的文件文件地址为:{}",filePath);
FileInputStream inputStream = new FileInputStream(files);
InputStream inputStream = this.getClass().getResourceAsStream(filePath);
//FileInputStream inputStream = //new FileInputStream(files);
//3.通过response获取ServletOutputStream对象(out) //3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream(); out = response.getOutputStream();
int b = 0; int b = 0;

Loading…
Cancel
Save