Amazon S3 をバージョン 1 URIsからバージョン 2 に解析する変更 - AWS SDK for Java 2.x

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon S3 をバージョン 1 URIsからバージョン 2 に解析する変更

このトピックでは、Amazon S3 をバージョン 1 (v1) URIsからバージョン 2 (v2) に解析する際の変更について詳しく説明します。

高レベル変更

v1 URIで S3 の解析を開始するには、コンストラクター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 変更

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");
クエリパラメータを取得します。 該当なし
Map<String, List<String>> queryParams = s3Uri.rawQueryParameters();

動作の変更

URL エンコーディング

v1 には、 をURLエンコードするかどうかを指定するフラグを渡すオプションURIがあります。デフォルト値は true です。

v2 では、URLエンコーディングはサポートされていません。予約または安全でない文字を持つオブジェクトキーまたはクエリパラメータを使用する場合は、それらをURLエンコードする必要があります。例えば、空白を " "に置き換える必要があります%20