|
@@ -193,8 +193,25 @@ public class SysOssServiceImpl extends BaseServiceImpl<SysOssMapper, SysOss> imp
|
|
|
String suffix = StringUtils.substring(name, name.lastIndexOf("."), name.length());
|
|
|
OssClient storage = OssFactory.instance();
|
|
|
UploadResult uploadResult;
|
|
|
- // TODO local情况处理 异步
|
|
|
- uploadResult = storage.uploadSuffix(file, suffix);
|
|
|
+ File tempFile = null;
|
|
|
+ try {
|
|
|
+ tempFile = File.createTempFile(name, suffix);
|
|
|
+ if (StrUtil.equals(storage.getConfigKey(), "local")) {
|
|
|
+ Map<String, String> map = commonService.uploadFile(FileUtils.fileToMultipartFile(tempFile));
|
|
|
+ uploadResult = UploadResult.builder().url(map.get("url")).filename(map.get("fileName")).build();
|
|
|
+ } else {
|
|
|
+ uploadResult = storage.uploadSuffix(file, suffix);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ // 删除临时文件(可选)
|
|
|
+ if (tempFile != null) {
|
|
|
+ FileUtil.del(tempFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
SysOssVo ossVo = buildResultEntity(name, suffix, storage.getConfigKey(), uploadResult);
|
|
|
return UploadRes.builder().name(name).url(uploadResult.getUrl()).ossId(ossVo.getOssId()).build();
|
|
|
}
|
|
@@ -208,7 +225,6 @@ public class SysOssServiceImpl extends BaseServiceImpl<SysOssMapper, SysOss> imp
|
|
|
UploadResult uploadResult;
|
|
|
try {
|
|
|
if (StrUtil.equals(storage.getConfigKey(), "local")) {
|
|
|
-
|
|
|
Map<String, String> map = commonService.uploadFile(FileUtils.fileToMultipartFile(file));
|
|
|
uploadResult = UploadResult.builder().url(map.get("url")).filename(map.get("fileName")).build();
|
|
|
} else {
|