拆分-图片-取消base64编码解决中文乱码问题

This commit is contained in:
liyawei
2022-06-10 16:43:03 +08:00
parent bc072cc262
commit c93ab796b3
4 changed files with 101 additions and 107 deletions
@@ -31,18 +31,18 @@ public class SplitFileController {
public void queryPageList(@RequestParam("fileUrl") String fileUrl, HttpServletResponse response, HttpServletRequest request) { public void queryPageList(@RequestParam("fileUrl") String fileUrl, HttpServletResponse response, HttpServletRequest request) {
//base64解码 //base64解码
BASE64Decoder base64Decoder = new BASE64Decoder(); // BASE64Decoder base64Decoder = new BASE64Decoder();
try { // try {
byte[] bytes = base64Decoder.decodeBuffer(fileUrl); // byte[] bytes = base64Decoder.decodeBuffer(fileUrl);
fileUrl = new String(bytes, "utf-8"); // fileUrl = new String(bytes, "utf-8");
} catch (IOException e) { // } catch (IOException e) {
throw new JeroBootException("文件不存在"); // throw new JeroBootException("文件不存在");
} // }
int splitIndex = fileUrl.lastIndexOf(File.separator); int splitIndex = fileUrl.lastIndexOf("/");
if(splitIndex == -1){ if(splitIndex == -1){
splitIndex = fileUrl.lastIndexOf("/"); splitIndex = fileUrl.lastIndexOf("/");
} }
String fileName = fileUrl.substring(splitIndex); String fileName = fileUrl.substring(splitIndex + 1);
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
"attachment; filename=\""+fileName+"\""); "attachment; filename=\""+fileName+"\"");
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
@@ -284,7 +284,6 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
} }
OSSFile oSSFile = new OSSFile(); OSSFile oSSFile = new OSSFile();
try {
String ctxPath = uploadCospath; String ctxPath = uploadCospath;
String fileName = null; String fileName = null;
String fileType = null; String fileType = null;
@@ -352,15 +351,11 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
oSSFile.setCreateTime(new Date()); oSSFile.setCreateTime(new Date());
this.save(oSSFile); this.save(oSSFile);
// 文件路径做特殊处理 // 文件路径做特殊处理
BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + filePath;
oSSFile.setUrl(imgUrl); oSSFile.setUrl(imgUrl);
return oSSFile; return oSSFile;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return oSSFile;
} }
@Override @Override
@@ -2570,9 +2570,9 @@ public class FileSpiltService {
try { try {
// String fileUrl = splitUrl + "/" + filepathandname; // String fileUrl = splitUrl + "/" + filepathandname;
BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
String encode = base64Encoder.encode(filepathandname.getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(filepathandname.getBytes(StandardCharsets.UTF_8));
String path = splitUrl+"/jero-boot/sys/split/file/getImage?fileUrl="+encode; String path = splitUrl+"/jero-boot/sys/split/file/getImage?fileUrl="+filepathandname;
CosBootUtil.uploadByte(bytev, filepathandname); CosBootUtil.uploadByte(bytev, filepathandname);
String imgCon = path; String imgCon = path;
String imgConVal = "<img class=\"wordImg\" src=\"" + path + "\">"; String imgConVal = "<img class=\"wordImg\" src=\"" + path + "\">";
@@ -1222,9 +1222,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
oSSFile = ossFileService.getById(oSSFile.getId()); oSSFile = ossFileService.getById(oSSFile.getId());
isText = false; isText = false;
BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1); // String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">"; String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
valEO.setType("IMG"); valEO.setType("IMG");
@@ -1272,9 +1272,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
oSSFile = ossFileService.getById(oSSFile.getId()); oSSFile = ossFileService.getById(oSSFile.getId());
isText = false; isText = false;
BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1); // String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">"; String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
valEO.setType("IMG"); valEO.setType("IMG");
@@ -1319,9 +1319,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if (oSSFile != null) { if (oSSFile != null) {
isText = false; isText = false;
BASE64Encoder base64Encoder = new BASE64Encoder(); // BASE64Encoder base64Encoder = new BASE64Encoder();
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8)); // String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1); // String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">"; String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
valEO.setType("IMG"); valEO.setType("IMG");
@@ -3169,17 +3169,16 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
fileSplitValImgExportDto.setImgName(imgUUIndex+".png"); fileSplitValImgExportDto.setImgName(imgUUIndex+".png");
String url = imgContent.substring(imgContent.lastIndexOf("=") + 1); String url = imgContent.substring(imgContent.lastIndexOf("=") + 1);
byte[] bytes = new byte[0]; // byte[] bytes = new byte[0];
try { // try {
bytes = base64Decoder.decodeBuffer(url); // bytes = base64Decoder.decodeBuffer(url);
url = new String(bytes, "utf-8"); // url = new String(bytes, "utf-8");
// }catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
fileSplitValImgExportDto.setImgPath(url); fileSplitValImgExportDto.setImgPath(url);
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// fileSplitValImgExportDto.setImgPath(imgContent.substring(imgContent.lastIndexOf(File.separator)+1)); // fileSplitValImgExportDto.setImgPath(imgContent.substring(imgContent.lastIndexOf(File.separator)+1));
allImgList.add(fileSplitValImgExportDto); allImgList.add(fileSplitValImgExportDto);