Skip to content

Commit

Permalink
reactor:优化file
Browse files Browse the repository at this point in the history
  • Loading branch information
KouShenhai committed Apr 23, 2023
1 parent db2d7b1 commit 7f64609
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public class FileUtil {
EXT_MAP.put("video", ".mp4,.MP4,.AVI,.mov,.rmvb,.rm,.FLV,.mp4,.3GP,.flv");
}

public static Boolean checkFileExt(String code,String fileSuffix) {
public static Boolean checkFileExt(String code,String fileExt) {
String extValue = EXT_MAP.get(code);
List<String> extList = Arrays.asList(extValue.split(Constant.COMMA));
return extList.contains(fileSuffix);
return extList.contains(fileExt);
}

/**
* 获取文件后缀
* @param fileName
* @return
*/
public static String getFileSuffix(String fileName) {
public static String getFileExt(String fileName) {
return fileName.substring(fileName.lastIndexOf(Constant.DOT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public String upload(int limitRead, long size, String fileName, InputStream inpu
* @param fileName
* @return
*/
public String getFileSuffix(String fileName) {
return FileUtil.getFileSuffix(fileName);
public String getFileExt(String fileName) {
return FileUtil.getFileExt(fileName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getUrl(AmazonS3 amazonS3,String fileName) {

@Override
public String getFileName(String fileName) {
return DateUtil.format(LocalDateTime.now(),DateUtil.YYYYMMDDHHMMSS) + getFileSuffix(fileName);
return DateUtil.format(LocalDateTime.now(),DateUtil.YYYYMMDDHHMMSS) + getFileExt(fileName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ public interface StorageService<O> {
* @param fileName
* @return
*/
String getFileSuffix(String fileName);
String getFileExt(String fileName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void downLoadResource(Long id, HttpServletResponse response) throws IOExc
SysResourceVO resource = sysResourceService.getResourceById(id);
response.setContentType("application/octet-stream");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + System.currentTimeMillis() + FileUtil.getFileSuffix(resource.getUrl()));
response.setHeader("Content-disposition", "attachment;filename=" + System.currentTimeMillis() + FileUtil.getFileExt(resource.getUrl()));
InputStream inputStream = FileUtil.getInputStream(resource.getUrl());
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.write(inputStream.readAllBytes(),outputStream);
Expand Down Expand Up @@ -204,8 +204,8 @@ public UploadVO uploadResource(String code, MultipartFile file, String md5) {
String contentType = file.getContentType();
// 判断类型
String fileName = file.getOriginalFilename();
String fileSuffix = FileUtil.getFileSuffix(fileName);
if (!FileUtil.checkFileExt(code,fileSuffix)) {
String fileExt = FileUtil.getFileExt(fileName);
if (!FileUtil.checkFileExt(code,fileExt)) {
throw new CustomException("格式不正确,请重新上传资源");
}
return ossTemplate.upload(size,md5,fileName,contentType,inputStream);
Expand Down

0 comments on commit 7f64609

Please sign in to comment.