|
@@ -1,6 +1,7 @@
|
|
package com.fdkankan.fusion.service.impl;
|
|
package com.fdkankan.fusion.service.impl;
|
|
|
|
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
|
|
+import com.fdkankan.fusion.common.OssPath;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
import com.fdkankan.fusion.common.util.LocalToOssUtil;
|
|
import com.fdkankan.fusion.common.util.LocalToOssUtil;
|
|
import com.fdkankan.fusion.common.util.ShellUtil;
|
|
import com.fdkankan.fusion.common.util.ShellUtil;
|
|
@@ -87,29 +88,18 @@ public class UploadService {
|
|
//获取文件后缀名
|
|
//获取文件后缀名
|
|
String suffixName = fileName.substring(fileName.lastIndexOf("."));
|
|
String suffixName = fileName.substring(fileName.lastIndexOf("."));
|
|
//重新生成文件名
|
|
//重新生成文件名
|
|
- if(newName){
|
|
|
|
- fileName = UUID.randomUUID().toString().replace("-","") ;
|
|
|
|
- }else {
|
|
|
|
- fileName= fileName.substring(0,fileName.lastIndexOf("."));
|
|
|
|
- }
|
|
|
|
- if(fileName.length() >50){
|
|
|
|
- fileName = fileName.substring(0,50);
|
|
|
|
|
|
+ String uuid = UUID.randomUUID().toString().replace("-","") ;
|
|
|
|
+ String ossPath = String.format(OssPath.MANAGE_FILE_PATH, uuid + suffixName);
|
|
|
|
+
|
|
|
|
+ localFile = new File(OssPath.localPath + ossPath);
|
|
|
|
+ if(!localFile.getParentFile().exists()){
|
|
|
|
+ localFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
- localFile = File.createTempFile(fileName + suffixName,suffixName);
|
|
|
|
file.transferTo(localFile);
|
|
file.transferTo(localFile);
|
|
- String path = localFile.getPath();
|
|
|
|
- localToOssUtil.uploadOss(path,filePathAdd+ fileName + suffixName);
|
|
|
|
- if(!localToOssUtil.existKey(filePathAdd + fileName + suffixName)){
|
|
|
|
- throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
|
|
|
|
- }
|
|
|
|
- return queryPath +filePathAdd+ URLEncoder.encode(fileName,"utf-8") + suffixName;
|
|
|
|
|
|
+ return localFile.getPath();
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
log.info("upload-error:{}",e);
|
|
log.info("upload-error:{}",e);
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
|
|
throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
|
|
- }finally {
|
|
|
|
- if(localFile!=null){
|
|
|
|
- localFile.delete();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|