minio上传失败前端无感知问题处理

This commit is contained in:
Chopper 2022-07-11 18:53:07 +08:00
parent 2c02b816b5
commit c663aa2799

View File

@ -1,5 +1,7 @@
package cn.lili.modules.file.plugin.impl; package cn.lili.modules.file.plugin.impl;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.modules.file.entity.enums.OssEnum; import cn.lili.modules.file.entity.enums.OssEnum;
import cn.lili.modules.file.plugin.FilePlugin; import cn.lili.modules.file.plugin.FilePlugin;
import cn.lili.modules.system.entity.dto.OssSetting; import cn.lili.modules.system.entity.dto.OssSetting;
@ -62,10 +64,9 @@ public class MinioFilePlugin implements FilePlugin {
public String pathUpload(String filePath, String key) { public String pathUpload(String filePath, String key) {
try { try {
return this.inputStreamUpload(new FileInputStream(filePath), key); return this.inputStreamUpload(new FileInputStream(filePath), key);
} catch (FileNotFoundException e) { } catch (Exception e) {
e.printStackTrace(); throw new ServiceException(ResultCode.OSS_DELETE_ERROR, e.getMessage());
} }
return null;
} }
@Override @Override
@ -80,12 +81,9 @@ public class MinioFilePlugin implements FilePlugin {
.contentType("image/png") .contentType("image/png")
.build(); .build();
client.putObject(putObjectArgs); client.putObject(putObjectArgs);
} catch (ErrorResponseException e) {
e.printStackTrace();
return null;
} catch (Exception e) { } catch (Exception e) {
log.error("上传失败2", e); log.error("上传失败2", e);
return null; throw new ServiceException(ResultCode.OSS_DELETE_ERROR, e.getMessage());
} }
//拼接出可访问的url地址 //拼接出可访问的url地址
return ossSetting.getM_endpoint() + "/" + bucket + "/" + key; return ossSetting.getM_endpoint() + "/" + bucket + "/" + key;
@ -129,8 +127,10 @@ public class MinioFilePlugin implements FilePlugin {
log.info("创建minio桶成功{}", ossSetting.getM_bucketName()); log.info("创建minio桶成功{}", ossSetting.getM_bucketName());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); //晴空配置
minioClient = null;
log.error("创建[{}]bucket失败", ossSetting.getM_bucketName()); log.error("创建[{}]bucket失败", ossSetting.getM_bucketName());
throw new ServiceException(ResultCode.OSS_DELETE_ERROR, e.getMessage());
} }
} }
} }