update 优化 去除OSS桶检测 桶不存在自然会报错无需额外检测

This commit is contained in:
疯狂的狮子Li 2024-10-31 17:59:56 +08:00
parent d89727725b
commit 5e7fb88762

View File

@ -21,7 +21,6 @@ import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import software.amazon.awssdk.transfer.s3.S3TransferManager;
import software.amazon.awssdk.transfer.s3.model.*;
@ -113,7 +112,6 @@ public class OssClient {
.serviceConfiguration(config)
.build();
checkBucket();
} catch (Exception e) {
if (e instanceof OssException) {
throw e;
@ -122,25 +120,6 @@ public class OssClient {
}
}
/**
* 检查桶是否存在
*
* @throws OssException 当创建存储桶时发生异常时抛出
*/
public void checkBucket() {
String bucketName = properties.getBucketName();
try {
// 尝试获取存储桶的信息
client.headBucket(x -> x.bucket(bucketName).build()).join();
} catch (Exception ex) {
if (ex.getCause() instanceof NoSuchBucketException) {
throw new OssException("Bucket桶是不存在的请核对配置信息:[" + ex.getMessage() + "]");
} else {
throw new OssException("判断Bucket是否存在失败请核对配置信息:[" + ex.getMessage() + "]");
}
}
}
/**
* 上传文件到 Amazon S3并返回上传结果
*