Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): multi bucket download data #5599

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: should this be tested on the secondary bucket instead? otherwise this test targets the same bucket as the previous ones since they default to the main bucket with no bucket specified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, let me include a to-do to add the secondary bucket after upload file/data is merged. Right now there's no way to upload to the secondary bucket.

).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 @@ -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
Loading