|
@@ -4,9 +4,11 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.manage.common.OssPath;
|
|
|
import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
import com.fdkankan.manage.common.ResultData;
|
|
|
import com.fdkankan.common.util.DateExtUtil;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.service.ICommonService;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -44,18 +46,26 @@ public class CommonServiceImpl implements ICommonService {
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
|
@Override
|
|
|
- public ResultData uploadFile(MultipartFile file) throws IOException {
|
|
|
- String uuid = UUID.randomUUID().toString();
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
|
|
|
- String ossPath = String.format(OssPath.MANAGE_FILE_PATH, DateUtil.format(Calendar.getInstance()
|
|
|
- .getTime(), DateExtUtil.dateStyle6), uuid + extName);
|
|
|
- File tempFile = File.createTempFile(uuid ,extName);
|
|
|
- file.transferTo(tempFile);
|
|
|
- fYunFileServiceInterface.uploadFile(tempFile.getPath(), ossPath);
|
|
|
- tempFile.deleteOnExit();
|
|
|
- String url = this.ossUrlPrefix + ossPath;
|
|
|
- return ResultData.ok(url);
|
|
|
+ public String uploadFile(MultipartFile file) throws IOException {
|
|
|
+ File tempFile = null;
|
|
|
+ try {
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
|
|
|
+ String ossPath = String.format(OssPath.MANAGE_FILE_PATH, DateUtil.format(Calendar.getInstance()
|
|
|
+ .getTime(), DateExtUtil.dateStyle6), uuid + extName);
|
|
|
+ tempFile = File.createTempFile(uuid ,extName);
|
|
|
+ file.transferTo(tempFile);
|
|
|
+ fYunFileServiceInterface.uploadFile(tempFile.getPath(), ossPath);
|
|
|
+ tempFile.deleteOnExit();
|
|
|
+ return this.ossUrlPrefix + ossPath;
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
|
|
|
+ }finally {
|
|
|
+ if(tempFile!= null){
|
|
|
+ tempFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|