feature 升级aws-s3到2.X版本

This commit is contained in:
David Wei 2024-01-08 23:57:41 +08:00
parent 0d3d9d359b
commit 7338d7cdc8
2 changed files with 18 additions and 10 deletions

View File

@ -29,16 +29,6 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</exclusion>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -74,6 +74,9 @@ public class OssClient {
createBucket();
} catch (Exception e) {
if (e instanceof OssException) {
throw e;
}
throw new OssException("配置错误! 请检查系统配置:[" + e.getMessage() + "]");
}
}
@ -168,6 +171,21 @@ public class OssClient {
return upload(file, getPath(properties.getPrefix(), suffix));
}
/**
* 获取文件元数据
*
* @param path 完整文件路径
*/
public HeadObjectResponse getObjectMetadata(String path) {
path = path.replace(getUrl() + "/", "");
HeadObjectRequest headObjectRequest = HeadObjectRequest.builder()
.bucket(properties.getBucketName())
.key(path)
.build();
return client.headObject(headObjectRequest);
}
public InputStream getObjectContent(String path) {
path = path.replace(getUrl() + "/", "");