从版本 1 升级到版本 2 时解析 Amazon S3 URI 发生的更改 - AWS SDK for Java 2.x

从版本 1 升级到版本 2 时解析 Amazon S3 URI 发生的更改

本主题详细说明了 Amazon S3 URI 从版本 1(v1)到版本 2(v2)发生的更改。

高级别更改

在 v1 中,要开始解析 S3 URI,可使用构造函数对 AmazonS3URI 进行实例化。在 v2 中,在 S3Utilities 的实例上调用 parseUri(),以便返回 S3URI

更改 v1 v2

Maven 依赖项

<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> <version>1.12.5871</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>s3</artifactId> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.27.212</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>s3</artifactId> </dependency> </dependencies>
软件包名称 com.amazonaws.services.s3 software.amazon.awssdk.services.s3
类名 AmazonS3URI S3URI

1 最新版本2 最新版本

API 更改

行为 v1 v2
解析 S3 URI。
URI uri = URI.create( "https://s3.amazonaws.com"); AmazonS3Uri s3Uri = new AmazonS3URI(uri, false);
S3Client s3Client = S3Client.create(); S3Utilities s3Utilities = s3Client.utilities(); S3Uri s3Uri = s3Utilities.parseUri(uri);
从 S3 URI 检索存储桶名称。
String bucket = s3Uri.getBucket();
Optional<String> bucket = s3Uri.bucket();
检索密钥。
String key = s3Uri.getKey();
Optional<String> key = s3Uri.key();
检索区域。
String region = s3Uri.getRegion();
Optional<Region> region = s3Uri.region(); String region; if (s3Uri.region().isPresent()) { region = s3Uri.region().get().id(); }

检索 S3 URI 是否为路径风格。

boolean isPathStyle = s3Uri.isPathStyle();
boolean isPathStyle = s3Uri.isPathStyle();
检索版本 ID。
String versionId = s3Uri.getVersionId();
Optional<String> versionId = s3Uri.firstMatchingRawQueryParameter("versionId");
检索查询参数。 不适用
Map<String, List<String>> queryParams = s3Uri.rawQueryParameters();

行为更改

URL 编码

v1 提供了传入标志的选项,用于指定 URI 是否应进行 URL 编码。默认值为 true

在 v2 中,不支持 URL 编码。如果您使用包含保留字符或不安全字符的对象键或查询参数,则必须对其进行 URL 编码。例如,您需要将空格 " " 替换为 %20