Skip to content

Commit

Permalink
feat(storage): multi bucket download data (#5599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey authored and Nika Hassani committed Nov 20, 2024
1 parent 6af829c commit f062068
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -14,20 +14,25 @@ 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<Object?> get props => [pluginOptions];
List<Object?> get props => [pluginOptions, bucket];

@override
String get runtimeTypeName => 'StorageDownloadDataOptions';

@override
Map<String, Object?> toJson() => {
'pluginOptions': pluginOptions?.toJson(),
'bucket': bucket,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ 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');

// 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',
),
options: StorageDownloadDataOptions(bucket: mainBucket),
).result;
expect(downloadResult.bytes, identityData);
expect(
downloadResult.downloadedItem.path,
'private/$userIdentityId/$identityName',
);
});
});

group('download progress', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface

final s3Options = StorageDownloadDataOptions(
pluginOptions: s3PluginOptions,
bucket: options?.bucket,
);

final bytes = BytesBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ class StorageS3Service {
FutureOr<void> Function()? onDone,
FutureOr<void> 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,
Expand Down

0 comments on commit f062068

Please sign in to comment.