添加exist

This commit is contained in:
Jerry Yan 2025-04-06 17:46:17 +08:00
parent c8874064f0
commit a46d4d8fac
4 changed files with 25 additions and 0 deletions

View File

@ -211,6 +211,14 @@ final public class AliOssAdapter extends AStorageAdapter {
}
}
@Override
public boolean isExists(String ...path) {
try (OSSWrapper wrapper = getOssClient()) {
OSS ossClient = wrapper.getOSSClient();
return ossClient.doesObjectExist(config.getBucketName(), buildPath(path));
}
}
private OSSWrapper getOssClient() {
OSS ossClient = new OSSClientBuilder().build(config.getEndpoint(), config.getAccessKeyId(), config.getAccessKeySecret());
return new OSSWrapper(ossClient);

View File

@ -206,6 +206,16 @@ public class AwsOssAdapter extends AStorageAdapter {
}
}
@Override
public boolean isExists(String... path) {
try (S3Wrapper wrapper = getS3Client()) {
AmazonS3Client s3Client = wrapper.getS3Client();
return s3Client.doesObjectExist(config.getBucketName(), buildPath(path));
} catch (Exception e) {
return false;
}
}
private S3Wrapper getS3Client() {
BasicAWSCredentials basicAwsCred = new BasicAWSCredentials(config.getAccessKeyId(), config.getAccessKeySecret());
ClientConfiguration clientConfiguration = new ClientConfiguration();

View File

@ -26,4 +26,6 @@ public interface IStorageAdapter {
List<StorageFileObject> listDir(String ...path);
boolean deleteDir(String ...path);
boolean setAcl(StorageAcl acl, String ...path);
boolean isExists(String ...path);
}

View File

@ -60,4 +60,9 @@ public class LocalStorageAdapter extends AStorageAdapter{
public boolean setAcl(StorageAcl acl, String... path) {
return false;
}
@Override
public boolean isExists(String... path) {
return false;
}
}