|
@@ -203,20 +203,12 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
private String mediaConvertOss(String mediaUrl) {
|
|
private String mediaConvertOss(String mediaUrl) {
|
|
//资源转换
|
|
//资源转换
|
|
MultipartFile multipartFile = FileUtil.urlToMultipartFile(mediaUrl);
|
|
MultipartFile multipartFile = FileUtil.urlToMultipartFile(mediaUrl);
|
|
- // 获取上传文件的MIME类型
|
|
|
|
- String contentType = multipartFile.getContentType();
|
|
|
|
- // 初始化文件格式为默认值
|
|
|
|
- String fileFormat = "jpg";
|
|
|
|
- // 判断MIME类型不为空并且包含"/"字符
|
|
|
|
- if (contentType != null && contentType.contains("/")) {
|
|
|
|
- fileFormat = contentType.substring(contentType.lastIndexOf("/") + 1);
|
|
|
|
- }
|
|
|
|
//生成唯一文件名
|
|
//生成唯一文件名
|
|
- String fileName = Long.toString(System.currentTimeMillis(), 36) + SecurityUtil.getUserId() + "." + fileFormat;
|
|
|
|
|
|
+ String fileName = Long.toString(System.currentTimeMillis(), 36) + SecurityUtil.getUserId() + ".jpg";
|
|
try {
|
|
try {
|
|
ossService.upload("image/" + fileName, multipartFile.getInputStream());
|
|
ossService.upload("image/" + fileName, multipartFile.getInputStream());
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- log.error("文件上传oss异常, mediaUrl : {}, fileFormat : {}, e : {}", mediaUrl, fileFormat, e.getMessage());
|
|
|
|
|
|
+ log.error("文件上传oss异常, mediaUrl : {}, e : {}", mediaUrl, e.getMessage());
|
|
throw new BaseException("文件上传oss异常");
|
|
throw new BaseException("文件上传oss异常");
|
|
}
|
|
}
|
|
//oss资源地址
|
|
//oss资源地址
|