登录上传 mov 文件异常的问题,删除临时文件
This commit is contained in:
parent
cbbe21f1b8
commit
6df346f3f7
@ -174,6 +174,7 @@ public class OssServiceImpl implements OssService {
|
||||
String url = null;
|
||||
Integer uploadType = configService.getConfig("upload", 1);
|
||||
|
||||
try {
|
||||
if (uploadType.equals(1)) {
|
||||
url = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + uploadName; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
@ -226,15 +227,8 @@ public class OssServiceImpl implements OssService {
|
||||
mediaDTO.setMedia_size(size);
|
||||
mediaDTO.setMedia_url(url);
|
||||
mediaDTO.setMedia_order(1);
|
||||
mediaDTO.setMedia_path("/".concat(dir).concat("/").concat(fileName));
|
||||
|
||||
if (uploadType.equals(1)) {
|
||||
mediaDTO.setMedia_domain(ConfigConstant.URL_BASE);
|
||||
} else if (uploadType.equals(2)) {
|
||||
mediaDTO.setMedia_path("/".concat(dir).concat("/").concat(uploadName));
|
||||
mediaDTO.setMedia_domain(getOssUrlPrefix().concat(ALIYUN_OSS_DIR_PREFIX));
|
||||
} else if (uploadType.equals(4)) {
|
||||
mediaDTO.setMedia_domain(TENGXUN_ENDPOINT.concat("/").concat(TENGXUN_DEFAULT_DIR));
|
||||
}
|
||||
mediaDTO.setMedia_time(new Date());
|
||||
mediaDTO.setMedia_desc("");
|
||||
mediaDTO.setMedia_duration(media_duration);
|
||||
@ -246,6 +240,26 @@ public class OssServiceImpl implements OssService {
|
||||
result.put("thumb", thumb_file_url);
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
// 删除临时文件
|
||||
try {
|
||||
File tempFile = new File(uploadPath);
|
||||
if (tempFile.exists()) {
|
||||
tempFile.delete();
|
||||
logger.info("临时文件已删除: {}", uploadPath);
|
||||
}
|
||||
|
||||
// 同时删除可能创建的封面文件
|
||||
String coverPath = uploadPath.replace("." + VideoUtil.getVideoFormat(uploadPath), ".jpg");
|
||||
File coverFile = new File(coverPath);
|
||||
if (coverFile.exists()) {
|
||||
coverFile.delete();
|
||||
logger.info("临时封面文件已删除: {}", coverPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("删除临时文件失败: {}", uploadPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map upload(MultipartFile file, UserDto user) {
|
||||
|
||||
@ -182,6 +182,7 @@ public class OssServiceImpl implements OssService {
|
||||
String ossUrl = null;
|
||||
Integer uploadType = configService.getConfig("upload", 1);
|
||||
|
||||
try {
|
||||
if (uploadType.equals(1)) {
|
||||
ossUrl = ConfigConstant.URL_BASE + "/admin/oss/upload/" + dir + "/" + uploadName; // 文件本地路径
|
||||
} else if (uploadType.equals(2)) {
|
||||
@ -241,7 +242,7 @@ public class OssServiceImpl implements OssService {
|
||||
mediaDTO.setMedia_size(size);
|
||||
mediaDTO.setMedia_url(ossUrl);
|
||||
mediaDTO.setMedia_order(1);
|
||||
mediaDTO.setMedia_path("/".concat(dir).concat("/").concat(fileName));
|
||||
mediaDTO.setMedia_path("/".concat(dir).concat("/").concat(uploadName));
|
||||
mediaDTO.setMedia_domain(getOssUrlPrefix().concat(ALIYUN_OSS_DIR_PREFIX));
|
||||
mediaDTO.setMedia_time(new Date());
|
||||
mediaDTO.setMedia_desc("");
|
||||
@ -254,6 +255,18 @@ public class OssServiceImpl implements OssService {
|
||||
result.put("thumb", thumb_file_url);
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
// 删除临时文件
|
||||
try {
|
||||
File tempFile = new File(uploadPath);
|
||||
if (tempFile.exists()) {
|
||||
tempFile.delete();
|
||||
logger.info("临时文件已删除: {}", uploadPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("删除临时文件失败: {}", uploadPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map upload(MultipartFile file, UserDto user) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user