Browse Source

oss方法优化

dev
jianjun 5 years ago
parent
commit
a4a1790ff5
  1. 4
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/AliyunCloudStorageService.java
  2. 7
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java
  3. 9
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java

4
epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/AliyunCloudStorageService.java

@ -117,7 +117,7 @@ public class AliyunCloudStorageService extends AbstractCloudStorageService {
OSSClient client = getOssClient(privacyType); OSSClient client = getOssClient(privacyType);
try { try {
client.deleteObject(props.getAliyunBucketName(), objectName); client.deleteObject(props.getAliyunBucketName(), objectName);
client.shutdown(); //client.shutdown();
} catch (Exception e){ } catch (Exception e){
return false; return false;
} }
@ -178,7 +178,7 @@ public class AliyunCloudStorageService extends AbstractCloudStorageService {
downloadRes.getObjectMetadata(); downloadRes.getObjectMetadata();
// 关闭OSSClient。 // 关闭OSSClient。
client.shutdown(); //client.shutdown();
} catch (Exception e){ } catch (Exception e){
throw new RenException(ModuleErrorCode.OSS_UPLOAD_FILE_ERROR, e, ""); throw new RenException(ModuleErrorCode.OSS_UPLOAD_FILE_ERROR, e, "");
} catch (Throwable throwable) { } catch (Throwable throwable) {

7
epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java

@ -232,18 +232,17 @@ public class OssController {
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode()
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg());
} }
long size = file.getSize();
if (ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) { if (ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) {
// 校验文件体积,不超过5m // 校验文件大小,不超过5m
long maxSize = 5 * 1024 * 1024; long maxSize = 5 * 1024 * 1024;
long size = file.getSize();
if (size > maxSize) { if (size > maxSize) {
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());
} }
} else { } else {
// 校验文件体积,不超过2m // 校验文件大小,不超过2m
long maxSize = 2 * 1024 * 1024; long maxSize = 2 * 1024 * 1024;
long size = file.getSize();
if (size > maxSize) { if (size > maxSize) {
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode()
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); , EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg());

9
epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java

@ -74,8 +74,7 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement
url = storageService.uploadSuffix(file.getBytes(), extension, privacy); url = storageService.uploadSuffix(file.getBytes(), extension, privacy);
ossDomain = storageService.getOssDomain(privacy); ossDomain = storageService.getOssDomain(privacy);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error("图片上传异常", e);
logger.error("图片上传异常");
throw new RenException("图片上传异常"); throw new RenException("图片上传异常");
} }
@ -134,8 +133,7 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement
try { try {
url = OssFactory.build().uploadSuffix(file.getBytes(), extension, PrivacyType.INTERNAL); url = OssFactory.build().uploadSuffix(file.getBytes(), extension, PrivacyType.INTERNAL);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error("文件上传异常", e);
logger.error("文件上传异常");
throw new RenException("文件上传异常"); throw new RenException("文件上传异常");
} }
//保存文件信息 //保存文件信息
@ -165,8 +163,7 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement
try { try {
url = OssFactory.build().uploadSuffix(file.getBytes(), extension, null); url = OssFactory.build().uploadSuffix(file.getBytes(), extension, null);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error("语音上传异常", e);
logger.error("语音上传异常");
throw new RenException("语音上传异常"); throw new RenException("语音上传异常");
} }

Loading…
Cancel
Save