從版本 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 中,您呼叫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 變更

Behavior (行為) 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");
擷取查詢參數。 N/A
Map<String, List<String>> queryParams = s3Uri.rawQueryParameters();

行為改變

网址编码

v1 提供了傳遞標誌的選項,以指定 URI 是否應該進行 URL 編碼。預設值為 true

在 v2 中,不支持 URL 編碼。如果您使用具有保留或不安全字元的物件索引鍵或查詢參數,則必須對其進行 URL 編碼。例如,您需要" "%20.