解析从版本 1 到版本 2 的 Amazon S3 URI 时发生的变化 - Amazon SDK for Java 2.x
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

解析从版本 1 到版本 2 的 Amazon S3 URI 时发生的变化

本主题详细介绍了在解析从版本 1 (v1) 到版本 2 (v2.) 的 Amazon S3 URI 时所做的更改。

高级别更改

要在 v1 中开始解析 S3 URI,请使用构造函数实例AmazonS3URI化。在 v2 中,你调用parseUri()一个的实例S3Utilities,以返回。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.21.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();

行为更改

网址编码

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

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