From 007643866abe5e70c05e16568470d472fa549cd5 Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Thu, 24 Oct 2024 12:28:51 -0500 Subject: [PATCH 1/3] feat(storage): multi bucket download data --- .../types/storage/download_data_options.dart | 9 +++++++-- .../integration_test/download_data_test.dart | 17 +++++++++++++++++ .../service/storage_s3_service_impl.dart | 7 ++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/amplify_core/lib/src/types/storage/download_data_options.dart b/packages/amplify_core/lib/src/types/storage/download_data_options.dart index 25c59523f1..020856dfe1 100644 --- a/packages/amplify_core/lib/src/types/storage/download_data_options.dart +++ b/packages/amplify_core/lib/src/types/storage/download_data_options.dart @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import 'package:aws_common/aws_common.dart'; +import 'package:amplify_core/amplify_core.dart'; /// {@template amplify_core.storage.download_data_options} /// Configurable options for `Amplify.Storage.downloadData`. @@ -14,13 +14,17 @@ class StorageDownloadDataOptions /// {@macro amplify_core.storage.download_data_options} const StorageDownloadDataOptions({ this.pluginOptions, + this.bucket, }); /// {@macro amplify_core.storage.download_data_plugin_options} final StorageDownloadDataPluginOptions? pluginOptions; + /// Optionally specify which bucket to target + final StorageBucket? bucket; + @override - List get props => [pluginOptions]; + List get props => [pluginOptions, bucket]; @override String get runtimeTypeName => 'StorageDownloadDataOptions'; @@ -28,6 +32,7 @@ class StorageDownloadDataOptions @override Map toJson() => { 'pluginOptions': pluginOptions?.toJson(), + 'bucket': bucket, }; } diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart index eb028d3919..eeba91495f 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart @@ -132,6 +132,23 @@ void main() { expect(utf8.decode(downloadResult.bytes), 'data'); expect(downloadResult.downloadedItem.path, publicPath); }); + + testWidgets('multi bucket', (_) async { + final mainBucket = + StorageBucket.fromOutputs('Storage Integ Test main bucket'); + + final downloadResult = await Amplify.Storage.downloadData( + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$identityName', + ), + options: StorageDownloadDataOptions(bucket: mainBucket), + ).result; + expect(downloadResult.bytes, identityData); + expect( + downloadResult.downloadedItem.path, + 'private/$userIdentityId/$identityName', + ); + }); }); group('download progress', () { diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart index a6feeb334d..7a503ee573 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart @@ -299,10 +299,11 @@ class StorageS3Service { FutureOr Function()? onDone, FutureOr Function()? onError, }) { + final s3ClientInfo = getS3ClientInfo(storageBucket: options.bucket); final downloadDataTask = S3DownloadTask( - s3Client: _defaultS3Client, - defaultS3ClientConfig: _defaultS3ClientConfig, - bucket: _storageOutputs.bucketName, + s3Client: s3ClientInfo.client, + defaultS3ClientConfig: s3ClientInfo.config, + bucket: s3ClientInfo.bucketName, path: path, options: options, pathResolver: _pathResolver, From 788a83817489dc18832b22d6777623966b6494fd Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Thu, 24 Oct 2024 12:46:22 -0500 Subject: [PATCH 2/3] added todo --- .../example/integration_test/download_data_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart index eeba91495f..a88c3631aa 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_data_test.dart @@ -137,6 +137,7 @@ void main() { final mainBucket = StorageBucket.fromOutputs('Storage Integ Test main bucket'); + // TODO(equartey): Add download check for secondary bucket when upload supports multibucket final downloadResult = await Amplify.Storage.downloadData( path: StoragePath.fromIdentityId( (identityId) => 'private/$identityId/$identityName', From edbaab3dfc15cf1221aba668dc9902a541615553 Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Fri, 25 Oct 2024 13:08:24 -0500 Subject: [PATCH 3/3] fix missing option --- .../lib/src/amplify_storage_s3_dart_impl.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart b/packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart index 5134b7a704..6797d91341 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart @@ -217,6 +217,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface final s3Options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, + bucket: options?.bucket, ); final bytes = BytesBuilder();