From e7e7c08c4a668d2b9ab9d49354dad30dc8203d78 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:32:03 -0800 Subject: [PATCH 01/16] Updated dowload file options to accept bucket parameter added integration tests --- .../types/storage/download_file_options.dart | 9 +- .../integration_test/download_file_test.dart | 214 ++++++++++++++++++ .../lib/src/amplify_storage_s3_dart_impl.dart | 5 +- .../download_file/download_file_html.dart | 4 +- .../download_file/download_file_io.dart | 1 + 5 files changed, 227 insertions(+), 6 deletions(-) diff --git a/packages/amplify_core/lib/src/types/storage/download_file_options.dart b/packages/amplify_core/lib/src/types/storage/download_file_options.dart index 8681667131..23d745f5e6 100644 --- a/packages/amplify_core/lib/src/types/storage/download_file_options.dart +++ b/packages/amplify_core/lib/src/types/storage/download_file_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_file_options} /// Configurable options for `Amplify.Storage.downloadFile`. @@ -14,13 +14,17 @@ class StorageDownloadFileOptions /// {@macro amplify_core.storage.download_file_options} const StorageDownloadFileOptions({ this.pluginOptions, + this.bucket, }); /// {@macro amplify_core.storage.download_file_plugin_options} final StorageDownloadFilePluginOptions? pluginOptions; + /// Optionally specify which bucket to target + final StorageBucket? bucket; + @override - List get props => [pluginOptions]; + List get props => [pluginOptions, bucket]; @override String get runtimeTypeName => 'StorageDownloadFileOptions'; @@ -28,6 +32,7 @@ class StorageDownloadFileOptions @override Map toJson() => { 'pluginOptions': pluginOptions?.toJson(), + 'bucket': bucket, }; } diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart index fb3dd7e554..937f80a6cb 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart @@ -296,5 +296,219 @@ void main() { }, ); }); + group('multibucket config', () { + final secondaryBucket = + StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); + setUpAll(() async { + await configure(amplifyEnvironments['main']!); + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(publicPath), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + + userIdentityId = await signInNewUser(); + identityPath = 'private/$userIdentityId/$name'; + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(metadataFilePath), + options: StorageUploadDataOptions( + metadata: metadata, + bucket: secondaryBucket, + ), + ).result; + + addTearDownPaths( + [ + StoragePath.fromString(publicPath), + StoragePath.fromString(metadataFilePath), + StoragePath.fromString(identityPath), + ], + ); + }); + + group('for file type', () { + testWidgets('to file', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + + // Web browsers do not grant access to read arbitrary files + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, publicPath); + }); + }); + + testWidgets('from identity ID', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, identityPath); + }); + + group('with options', () { + testWidgets('useAccelerateEndpoint', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + options: StorageDownloadFileOptions( + pluginOptions: const S3DownloadFilePluginOptions( + useAccelerateEndpoint: true, + ), + bucket: secondaryBucket, + ), + localFile: AWSFile.fromPath(downloadFilePath), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, publicPath); + }); + + testWidgets('getProperties', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + final downloadResult = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(metadataFilePath), + options: StorageDownloadFileOptions( + pluginOptions: const S3DownloadFilePluginOptions( + getProperties: true, + ), + bucket: secondaryBucket, + ), + localFile: AWSFile.fromPath(downloadFilePath), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(downloadResult.localFile.path, downloadFilePath); + expect(downloadResult.downloadedItem.path, metadataFilePath); + }); + + testWidgets('unauthorized path', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + await expectLater( + () => Amplify.Storage.downloadFile( + path: const StoragePath.fromString('unauthorized/path'), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result, + throwsA(isA()), + ); + }); + }); + + group( + 'download progress', + () { + testWidgets('reports progress', skip: kIsWeb, (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + var fractionCompleted = 0.0; + var totalBytes = 0; + var transferredBytes = 0; + + await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + localFile: AWSFile.fromPath(downloadFilePath), + onProgress: (StorageTransferProgress progress) { + fractionCompleted = progress.fractionCompleted; + totalBytes = progress.totalBytes; + transferredBytes = progress.transferredBytes; + }, + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + expect(fractionCompleted, 1.0); + expect(totalBytes, data.length); + expect(transferredBytes, data.length); + }); + }, + // TODO(Jordan-Nelson): Determine why these are failing on web + skip: kIsWeb, + ); + + group( + 'pause, resume, cancel', + () { + const size = 1024 * 1024 * 6; + const chars = 'qwertyuiopasdfghjklzxcvbnm'; + final content = List.generate(size, (i) => chars[i % 25]).join(); + final fileId = uuid(); + final path = 'public/download-file-pause-$fileId'; + setUpAll(() async { + addTearDownPath(StoragePath.fromString(path)); + await Amplify.Storage.uploadData( + data: StorageDataPayload.string(content), + path: StoragePath.fromString(path), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + }); + testWidgets('can pause', (_) async { + final filePath = '$directory/downloaded-file.txt'; + final operation = Amplify.Storage.downloadFile( + localFile: AWSFile.fromPath(filePath), + path: StoragePath.fromString(path), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ); + await operation.pause(); + unawaited( + operation.result.then( + (value) => fail('should not complete after pause'), + ), + ); + await Future.delayed(const Duration(seconds: 15)); + }); + + testWidgets('can resume', (_) async { + final filePath = '$directory/downloaded-file.txt'; + final operation = Amplify.Storage.downloadFile( + localFile: AWSFile.fromPath(filePath), + path: StoragePath.fromString(path), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ); + await operation.pause(); + await operation.resume(); + final result = await operation.result; + expect(result.downloadedItem.path, path); + }); + }, + // TODO(Jordan-Nelson): Determine why these are failing on web + skip: kIsWeb, + ); + }); }); } 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 3abc9c7490..ad97e00a4c 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 @@ -258,13 +258,14 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - options = StorageDownloadFileOptions( + final s3options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, + bucket: options?.bucket, ); return download_file_impl.downloadFile( path: path, localFile: localFile, - options: options, + options: s3options, storageOutputs: storageOutputs, storageS3Service: storageS3Service, appPathProvider: _appPathProvider, diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index 32f79a9d38..aa1d2e9c4b 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -40,7 +40,7 @@ S3DownloadFileOperation downloadFile({ cancel: noOp, ); } - +// TODO: add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, @@ -58,7 +58,7 @@ Future _downloadFromUrl({ // operation. final downloadedItem = (await storageS3Service.getProperties( path: path, - options: const StorageGetPropertiesOptions(), + options: StorageGetPropertiesOptions(bucket: options.bucket), )) .storageItem; diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_io.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_io.dart index 5651870acd..c17e19b1db 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_io.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_io.dart @@ -32,6 +32,7 @@ S3DownloadFileOperation downloadFile({ getProperties: s3PluginOptions.getProperties, useAccelerateEndpoint: s3PluginOptions.useAccelerateEndpoint, ), + bucket: options.bucket, ); final downloadDataTask = storageS3Service.downloadData( From 0d4e7a0fd87837cd01e1b1a23926c746430e70a9 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:41:18 -0800 Subject: [PATCH 02/16] updated todo message --- .../src/platform_impl/download_file/download_file_html.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index aa1d2e9c4b..dc46eba874 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -40,7 +40,8 @@ S3DownloadFileOperation downloadFile({ cancel: noOp, ); } -// TODO: add bucket option to function once getURL update has been implemented + +// TODO(ekjotm): add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, From 65de3c7be67fe82b15d79aefb9d7760b7ccd87c9 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:38:36 -0800 Subject: [PATCH 03/16] updates variable names and tests --- .../integration_test/download_file_test.dart | 275 ++++-------------- .../lib/src/amplify_storage_s3_dart_impl.dart | 6 +- 2 files changed, 63 insertions(+), 218 deletions(-) diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart index 937f80a6cb..4ed64792e5 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart @@ -28,7 +28,8 @@ void main() { final name = 'download-file-with-identity-id-${uuid()}'; final metadataFilePath = 'public/download-file-get-properties-${uuid()}'; final metadata = {'description': 'foo'}; - + final secondaryBucket = + StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); setUpAll(() async { directory = kIsWeb ? '/' : (await getTemporaryDirectory()).path; }); @@ -51,6 +52,22 @@ void main() { ), ).result; + // secondary bucket uploads + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(publicPath), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + await Amplify.Storage.uploadData( data: StorageDataPayload.bytes(data), path: StoragePath.fromString(metadataFilePath), @@ -68,6 +85,48 @@ void main() { ); }); + group('multibucket', () { + testWidgets('to file', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions( + bucket: secondaryBucket, + ), + ).result; + + // Web browsers do not grant access to read arbitrary files + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, publicPath); + }); + testWidgets('from identity ID', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions( + bucket: secondaryBucket, + ), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, identityPath); + }); + }); + group('for file type', () { testWidgets('to file', (_) async { final downloadFilePath = '$directory/downloaded-file.txt'; @@ -296,219 +355,5 @@ void main() { }, ); }); - group('multibucket config', () { - final secondaryBucket = - StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); - setUpAll(() async { - await configure(amplifyEnvironments['main']!); - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromString(publicPath), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - - userIdentityId = await signInNewUser(); - identityPath = 'private/$userIdentityId/$name'; - - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromIdentityId( - (identityId) => 'private/$identityId/$name', - ), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromString(metadataFilePath), - options: StorageUploadDataOptions( - metadata: metadata, - bucket: secondaryBucket, - ), - ).result; - - addTearDownPaths( - [ - StoragePath.fromString(publicPath), - StoragePath.fromString(metadataFilePath), - StoragePath.fromString(identityPath), - ], - ); - }); - - group('for file type', () { - testWidgets('to file', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - - // Web browsers do not grant access to read arbitrary files - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, publicPath); - }); - }); - - testWidgets('from identity ID', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromIdentityId( - (identityId) => 'private/$identityId/$name', - ), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, identityPath); - }); - - group('with options', () { - testWidgets('useAccelerateEndpoint', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - options: StorageDownloadFileOptions( - pluginOptions: const S3DownloadFilePluginOptions( - useAccelerateEndpoint: true, - ), - bucket: secondaryBucket, - ), - localFile: AWSFile.fromPath(downloadFilePath), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, publicPath); - }); - - testWidgets('getProperties', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - final downloadResult = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(metadataFilePath), - options: StorageDownloadFileOptions( - pluginOptions: const S3DownloadFilePluginOptions( - getProperties: true, - ), - bucket: secondaryBucket, - ), - localFile: AWSFile.fromPath(downloadFilePath), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(downloadResult.localFile.path, downloadFilePath); - expect(downloadResult.downloadedItem.path, metadataFilePath); - }); - - testWidgets('unauthorized path', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - await expectLater( - () => Amplify.Storage.downloadFile( - path: const StoragePath.fromString('unauthorized/path'), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result, - throwsA(isA()), - ); - }); - }); - - group( - 'download progress', - () { - testWidgets('reports progress', skip: kIsWeb, (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - var fractionCompleted = 0.0; - var totalBytes = 0; - var transferredBytes = 0; - - await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - localFile: AWSFile.fromPath(downloadFilePath), - onProgress: (StorageTransferProgress progress) { - fractionCompleted = progress.fractionCompleted; - totalBytes = progress.totalBytes; - transferredBytes = progress.transferredBytes; - }, - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - expect(fractionCompleted, 1.0); - expect(totalBytes, data.length); - expect(transferredBytes, data.length); - }); - }, - // TODO(Jordan-Nelson): Determine why these are failing on web - skip: kIsWeb, - ); - - group( - 'pause, resume, cancel', - () { - const size = 1024 * 1024 * 6; - const chars = 'qwertyuiopasdfghjklzxcvbnm'; - final content = List.generate(size, (i) => chars[i % 25]).join(); - final fileId = uuid(); - final path = 'public/download-file-pause-$fileId'; - setUpAll(() async { - addTearDownPath(StoragePath.fromString(path)); - await Amplify.Storage.uploadData( - data: StorageDataPayload.string(content), - path: StoragePath.fromString(path), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - }); - testWidgets('can pause', (_) async { - final filePath = '$directory/downloaded-file.txt'; - final operation = Amplify.Storage.downloadFile( - localFile: AWSFile.fromPath(filePath), - path: StoragePath.fromString(path), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ); - await operation.pause(); - unawaited( - operation.result.then( - (value) => fail('should not complete after pause'), - ), - ); - await Future.delayed(const Duration(seconds: 15)); - }); - - testWidgets('can resume', (_) async { - final filePath = '$directory/downloaded-file.txt'; - final operation = Amplify.Storage.downloadFile( - localFile: AWSFile.fromPath(filePath), - path: StoragePath.fromString(path), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ); - await operation.pause(); - await operation.resume(); - final result = await operation.result; - expect(result.downloadedItem.path, path); - }); - }, - // TODO(Jordan-Nelson): Determine why these are failing on web - skip: kIsWeb, - ); - }); }); } 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 ad97e00a4c..8bae563b24 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 @@ -216,8 +216,8 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - - final s3Options = StorageDownloadDataOptions( + + options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); @@ -225,7 +225,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface final bytes = BytesBuilder(); final downloadTask = storageS3Service.downloadData( path: path, - options: s3Options, + options: options, onProgress: onProgress, onData: bytes.add, ); From 2bdbada2da7715398cdee92eac17c0a54480eb77 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:10:04 -0800 Subject: [PATCH 04/16] Update packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart Co-authored-by: NikaHsn --- .../lib/src/amplify_storage_s3_dart_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8bae563b24..f53d4baf51 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 @@ -258,7 +258,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - final s3options = StorageDownloadFileOptions( + final options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); From 27c612fbc57c1a8bee065afb2bc8132365ca7d8e Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:29:15 -0800 Subject: [PATCH 05/16] updated variable names to match --- .../lib/src/amplify_storage_s3_dart_impl.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f53d4baf51..7823669da2 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 @@ -258,14 +258,14 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - final options = StorageDownloadFileOptions( + options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); return download_file_impl.downloadFile( path: path, localFile: localFile, - options: s3options, + options: options, storageOutputs: storageOutputs, storageS3Service: storageS3Service, appPathProvider: _appPathProvider, From edd7afd63baf8644cb45f1dc3fe6de4ca8603761 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:16:48 -0800 Subject: [PATCH 06/16] formatting --- .../lib/src/amplify_storage_s3_dart_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7823669da2..5bf1a6022a 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 @@ -216,7 +216,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - + options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, From 6eb10a9efa576c93e887680df5d9cd94ac56e861 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:57:35 -0800 Subject: [PATCH 07/16] reverted variable name change --- .../lib/src/amplify_storage_s3_dart_impl.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 5bf1a6022a..f754941b43 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,7 +217,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - options = StorageDownloadDataOptions( + final s3Options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); @@ -225,7 +225,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface final bytes = BytesBuilder(); final downloadTask = storageS3Service.downloadData( path: path, - options: options, + options: s3Options, onProgress: onProgress, onData: bytes.add, ); From 1fd189d70095217f85d2fa0d685253d2e2b544d0 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:01:47 -0800 Subject: [PATCH 08/16] updated html implementation of downloadFIle --- .../lib/src/platform_impl/download_file/download_file_html.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index dc46eba874..a77ee6f8c5 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -41,7 +41,6 @@ S3DownloadFileOperation downloadFile({ ); } -// TODO(ekjotm): add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, @@ -72,6 +71,7 @@ Future _downloadFromUrl({ pluginOptions: S3GetUrlPluginOptions( useAccelerateEndpoint: s3PluginOptions.useAccelerateEndpoint, ), + bucket: options.bucket, ), )) .url; From e2ca2ddaebfa0617d60d436ae7435b5ca72fa57c Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:32:03 -0800 Subject: [PATCH 09/16] Updated dowload file options to accept bucket parameter added integration tests --- .../integration_test/download_file_test.dart | 214 ++++++++++++++++++ .../lib/src/amplify_storage_s3_dart_impl.dart | 4 +- .../download_file/download_file_html.dart | 2 +- 3 files changed, 217 insertions(+), 3 deletions(-) diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart index 4ed64792e5..db8422fec2 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart @@ -355,5 +355,219 @@ void main() { }, ); }); + group('multibucket config', () { + final secondaryBucket = + StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); + setUpAll(() async { + await configure(amplifyEnvironments['main']!); + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(publicPath), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + + userIdentityId = await signInNewUser(); + identityPath = 'private/$userIdentityId/$name'; + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(metadataFilePath), + options: StorageUploadDataOptions( + metadata: metadata, + bucket: secondaryBucket, + ), + ).result; + + addTearDownPaths( + [ + StoragePath.fromString(publicPath), + StoragePath.fromString(metadataFilePath), + StoragePath.fromString(identityPath), + ], + ); + }); + + group('for file type', () { + testWidgets('to file', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + + // Web browsers do not grant access to read arbitrary files + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, publicPath); + }); + }); + + testWidgets('from identity ID', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromIdentityId( + (identityId) => 'private/$identityId/$name', + ), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, identityPath); + }); + + group('with options', () { + testWidgets('useAccelerateEndpoint', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + final result = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + options: StorageDownloadFileOptions( + pluginOptions: const S3DownloadFilePluginOptions( + useAccelerateEndpoint: true, + ), + bucket: secondaryBucket, + ), + localFile: AWSFile.fromPath(downloadFilePath), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(result.localFile.path, downloadFilePath); + expect(result.downloadedItem.path, publicPath); + }); + + testWidgets('getProperties', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + final downloadResult = await Amplify.Storage.downloadFile( + path: StoragePath.fromString(metadataFilePath), + options: StorageDownloadFileOptions( + pluginOptions: const S3DownloadFilePluginOptions( + getProperties: true, + ), + bucket: secondaryBucket, + ), + localFile: AWSFile.fromPath(downloadFilePath), + ).result; + + if (!kIsWeb) { + final downloadedFile = await readFile(path: downloadFilePath); + expect(downloadedFile, data); + } + expect(downloadResult.localFile.path, downloadFilePath); + expect(downloadResult.downloadedItem.path, metadataFilePath); + }); + + testWidgets('unauthorized path', (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + + await expectLater( + () => Amplify.Storage.downloadFile( + path: const StoragePath.fromString('unauthorized/path'), + localFile: AWSFile.fromPath(downloadFilePath), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result, + throwsA(isA()), + ); + }); + }); + + group( + 'download progress', + () { + testWidgets('reports progress', skip: kIsWeb, (_) async { + final downloadFilePath = '$directory/downloaded-file.txt'; + var fractionCompleted = 0.0; + var totalBytes = 0; + var transferredBytes = 0; + + await Amplify.Storage.downloadFile( + path: StoragePath.fromString(publicPath), + localFile: AWSFile.fromPath(downloadFilePath), + onProgress: (StorageTransferProgress progress) { + fractionCompleted = progress.fractionCompleted; + totalBytes = progress.totalBytes; + transferredBytes = progress.transferredBytes; + }, + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ).result; + expect(fractionCompleted, 1.0); + expect(totalBytes, data.length); + expect(transferredBytes, data.length); + }); + }, + // TODO(Jordan-Nelson): Determine why these are failing on web + skip: kIsWeb, + ); + + group( + 'pause, resume, cancel', + () { + const size = 1024 * 1024 * 6; + const chars = 'qwertyuiopasdfghjklzxcvbnm'; + final content = List.generate(size, (i) => chars[i % 25]).join(); + final fileId = uuid(); + final path = 'public/download-file-pause-$fileId'; + setUpAll(() async { + addTearDownPath(StoragePath.fromString(path)); + await Amplify.Storage.uploadData( + data: StorageDataPayload.string(content), + path: StoragePath.fromString(path), + options: StorageUploadDataOptions(bucket: secondaryBucket), + ).result; + }); + testWidgets('can pause', (_) async { + final filePath = '$directory/downloaded-file.txt'; + final operation = Amplify.Storage.downloadFile( + localFile: AWSFile.fromPath(filePath), + path: StoragePath.fromString(path), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ); + await operation.pause(); + unawaited( + operation.result.then( + (value) => fail('should not complete after pause'), + ), + ); + await Future.delayed(const Duration(seconds: 15)); + }); + + testWidgets('can resume', (_) async { + final filePath = '$directory/downloaded-file.txt'; + final operation = Amplify.Storage.downloadFile( + localFile: AWSFile.fromPath(filePath), + path: StoragePath.fromString(path), + options: StorageDownloadFileOptions(bucket: secondaryBucket), + ); + await operation.pause(); + await operation.resume(); + final result = await operation.result; + expect(result.downloadedItem.path, path); + }); + }, + // TODO(Jordan-Nelson): Determine why these are failing on web + skip: kIsWeb, + ); + }); }); } 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 f754941b43..ad97e00a4c 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 @@ -258,14 +258,14 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - options = StorageDownloadFileOptions( + final s3options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); return download_file_impl.downloadFile( path: path, localFile: localFile, - options: options, + options: s3options, storageOutputs: storageOutputs, storageS3Service: storageS3Service, appPathProvider: _appPathProvider, diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index a77ee6f8c5..3b49cbf7d7 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -40,7 +40,7 @@ S3DownloadFileOperation downloadFile({ cancel: noOp, ); } - +// TODO: add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, From 8bb047b1bb7c678ff5d84cca8df4da8b5bc3c51e Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:41:18 -0800 Subject: [PATCH 10/16] updated todo message --- .../src/platform_impl/download_file/download_file_html.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index 3b49cbf7d7..14875bd816 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -40,7 +40,8 @@ S3DownloadFileOperation downloadFile({ cancel: noOp, ); } -// TODO: add bucket option to function once getURL update has been implemented + +// TODO(ekjotm): add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, From c43dc943654fdaebf4b9708e35ff9f9d0ae8e6a5 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:38:36 -0800 Subject: [PATCH 11/16] updates variable names and tests --- .../integration_test/download_file_test.dart | 214 ------------------ .../lib/src/amplify_storage_s3_dart_impl.dart | 6 +- 2 files changed, 3 insertions(+), 217 deletions(-) diff --git a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart index db8422fec2..4ed64792e5 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/download_file_test.dart @@ -355,219 +355,5 @@ void main() { }, ); }); - group('multibucket config', () { - final secondaryBucket = - StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); - setUpAll(() async { - await configure(amplifyEnvironments['main']!); - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromString(publicPath), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - - userIdentityId = await signInNewUser(); - identityPath = 'private/$userIdentityId/$name'; - - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromIdentityId( - (identityId) => 'private/$identityId/$name', - ), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - - await Amplify.Storage.uploadData( - data: StorageDataPayload.bytes(data), - path: StoragePath.fromString(metadataFilePath), - options: StorageUploadDataOptions( - metadata: metadata, - bucket: secondaryBucket, - ), - ).result; - - addTearDownPaths( - [ - StoragePath.fromString(publicPath), - StoragePath.fromString(metadataFilePath), - StoragePath.fromString(identityPath), - ], - ); - }); - - group('for file type', () { - testWidgets('to file', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - - // Web browsers do not grant access to read arbitrary files - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, publicPath); - }); - }); - - testWidgets('from identity ID', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromIdentityId( - (identityId) => 'private/$identityId/$name', - ), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, identityPath); - }); - - group('with options', () { - testWidgets('useAccelerateEndpoint', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - final result = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - options: StorageDownloadFileOptions( - pluginOptions: const S3DownloadFilePluginOptions( - useAccelerateEndpoint: true, - ), - bucket: secondaryBucket, - ), - localFile: AWSFile.fromPath(downloadFilePath), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(result.localFile.path, downloadFilePath); - expect(result.downloadedItem.path, publicPath); - }); - - testWidgets('getProperties', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - final downloadResult = await Amplify.Storage.downloadFile( - path: StoragePath.fromString(metadataFilePath), - options: StorageDownloadFileOptions( - pluginOptions: const S3DownloadFilePluginOptions( - getProperties: true, - ), - bucket: secondaryBucket, - ), - localFile: AWSFile.fromPath(downloadFilePath), - ).result; - - if (!kIsWeb) { - final downloadedFile = await readFile(path: downloadFilePath); - expect(downloadedFile, data); - } - expect(downloadResult.localFile.path, downloadFilePath); - expect(downloadResult.downloadedItem.path, metadataFilePath); - }); - - testWidgets('unauthorized path', (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - - await expectLater( - () => Amplify.Storage.downloadFile( - path: const StoragePath.fromString('unauthorized/path'), - localFile: AWSFile.fromPath(downloadFilePath), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result, - throwsA(isA()), - ); - }); - }); - - group( - 'download progress', - () { - testWidgets('reports progress', skip: kIsWeb, (_) async { - final downloadFilePath = '$directory/downloaded-file.txt'; - var fractionCompleted = 0.0; - var totalBytes = 0; - var transferredBytes = 0; - - await Amplify.Storage.downloadFile( - path: StoragePath.fromString(publicPath), - localFile: AWSFile.fromPath(downloadFilePath), - onProgress: (StorageTransferProgress progress) { - fractionCompleted = progress.fractionCompleted; - totalBytes = progress.totalBytes; - transferredBytes = progress.transferredBytes; - }, - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ).result; - expect(fractionCompleted, 1.0); - expect(totalBytes, data.length); - expect(transferredBytes, data.length); - }); - }, - // TODO(Jordan-Nelson): Determine why these are failing on web - skip: kIsWeb, - ); - - group( - 'pause, resume, cancel', - () { - const size = 1024 * 1024 * 6; - const chars = 'qwertyuiopasdfghjklzxcvbnm'; - final content = List.generate(size, (i) => chars[i % 25]).join(); - final fileId = uuid(); - final path = 'public/download-file-pause-$fileId'; - setUpAll(() async { - addTearDownPath(StoragePath.fromString(path)); - await Amplify.Storage.uploadData( - data: StorageDataPayload.string(content), - path: StoragePath.fromString(path), - options: StorageUploadDataOptions(bucket: secondaryBucket), - ).result; - }); - testWidgets('can pause', (_) async { - final filePath = '$directory/downloaded-file.txt'; - final operation = Amplify.Storage.downloadFile( - localFile: AWSFile.fromPath(filePath), - path: StoragePath.fromString(path), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ); - await operation.pause(); - unawaited( - operation.result.then( - (value) => fail('should not complete after pause'), - ), - ); - await Future.delayed(const Duration(seconds: 15)); - }); - - testWidgets('can resume', (_) async { - final filePath = '$directory/downloaded-file.txt'; - final operation = Amplify.Storage.downloadFile( - localFile: AWSFile.fromPath(filePath), - path: StoragePath.fromString(path), - options: StorageDownloadFileOptions(bucket: secondaryBucket), - ); - await operation.pause(); - await operation.resume(); - final result = await operation.result; - expect(result.downloadedItem.path, path); - }); - }, - // TODO(Jordan-Nelson): Determine why these are failing on web - skip: kIsWeb, - ); - }); }); } 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 ad97e00a4c..8bae563b24 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 @@ -216,8 +216,8 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - - final s3Options = StorageDownloadDataOptions( + + options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); @@ -225,7 +225,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface final bytes = BytesBuilder(); final downloadTask = storageS3Service.downloadData( path: path, - options: s3Options, + options: options, onProgress: onProgress, onData: bytes.add, ); From a358c5c7e489d6b791ad8a83d949b3b496530408 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:10:04 -0800 Subject: [PATCH 12/16] Update packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart Co-authored-by: NikaHsn --- .../lib/src/amplify_storage_s3_dart_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8bae563b24..f53d4baf51 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 @@ -258,7 +258,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - final s3options = StorageDownloadFileOptions( + final options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); From 71c9e2ca159ad80c6c317176eb59a21a854767ca Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:29:15 -0800 Subject: [PATCH 13/16] updated variable names to match --- .../lib/src/amplify_storage_s3_dart_impl.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f53d4baf51..7823669da2 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 @@ -258,14 +258,14 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadFilePluginOptions(), ); - final options = StorageDownloadFileOptions( + options = StorageDownloadFileOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); return download_file_impl.downloadFile( path: path, localFile: localFile, - options: s3options, + options: options, storageOutputs: storageOutputs, storageS3Service: storageS3Service, appPathProvider: _appPathProvider, From d51dfba8999f9658f6ccf984acfce598da89216d Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:16:48 -0800 Subject: [PATCH 14/16] formatting --- .../lib/src/amplify_storage_s3_dart_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7823669da2..5bf1a6022a 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 @@ -216,7 +216,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface pluginOptions: options?.pluginOptions, defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - + options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, From 324febe20bb785cb3bb269fc77afad221d0fb349 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:05:20 -0800 Subject: [PATCH 15/16] reverted variable name change --- .../lib/src/amplify_storage_s3_dart_impl.dart | 4 ++-- .../src/platform_impl/download_file/download_file_html.dart | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) 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 5bf1a6022a..50429c95c1 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,7 +217,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - options = StorageDownloadDataOptions( + final s3Options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, ); @@ -225,7 +225,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface final bytes = BytesBuilder(); final downloadTask = storageS3Service.downloadData( path: path, - options: options, + options: s3Options, onProgress: onProgress, onData: bytes.add, ); diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart index 14875bd816..a77ee6f8c5 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/platform_impl/download_file/download_file_html.dart @@ -41,7 +41,6 @@ S3DownloadFileOperation downloadFile({ ); } -// TODO(ekjotm): add bucket option to function once getURL update has been implemented Future _downloadFromUrl({ required StoragePath path, required AWSFile localFile, From 41e5ecdaab706826276ccae26185bb6cf3e96a07 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:12:40 -0800 Subject: [PATCH 16/16] formatting --- .../lib/src/amplify_storage_s3_dart_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 50429c95c1..f754941b43 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,7 +217,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface defaultPluginOptions: const S3DownloadDataPluginOptions(), ); - final s3Options = StorageDownloadDataOptions( + final s3Options = StorageDownloadDataOptions( pluginOptions: s3PluginOptions, bucket: options?.bucket, );