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!: Update storage APIs to accept StoragePath #4549

Merged
merged 42 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fc906bb
chore: add `StoragePath`
Jordan-Nelson Mar 11, 2024
b100b26
chore: add `S3PathResolver`
Jordan-Nelson Mar 11, 2024
c729965
chore: update `getUrl` and `getProperties` API
Jordan-Nelson Mar 11, 2024
f738300
chore: update S3UploadTask
Jordan-Nelson Mar 11, 2024
2a91537
chore: fix tests
Jordan-Nelson Mar 12, 2024
d9fe4ef
chore: validate storage path
Jordan-Nelson Mar 12, 2024
d30a309
chore: add tests for S3PathResolver
Jordan-Nelson Mar 12, 2024
ff5f13d
feat: Gen 2 Upload APIs (#4542)
khatruong2009 Mar 13, 2024
adb8672
chore: refactor StoragePath (#4544)
Jordan-Nelson Mar 13, 2024
73810c8
chore: remove `key` from public APIs
Jordan-Nelson Mar 13, 2024
4f46a80
chore: update tests to adjust for using path
khatruong2009 Mar 14, 2024
f0cb5a2
chore: fix lint issues
Jordan-Nelson Mar 15, 2024
9918f95
chore: fix formatting
Jordan-Nelson Mar 15, 2024
3d0802f
chore: fix test
Jordan-Nelson Mar 15, 2024
4b9ffc2
chore: remove lint ignored
Jordan-Nelson Mar 15, 2024
ff67c0e
chore: update comment
Jordan-Nelson Mar 15, 2024
9b704d0
chore: remove unused method
Jordan-Nelson Mar 15, 2024
f5bb1cf
chore: skip tests other than main
Jordan-Nelson Mar 15, 2024
20026ec
chore: update generated code
Jordan-Nelson Mar 18, 2024
d150757
chore: add leading `/`
Jordan-Nelson Mar 18, 2024
fe28a87
feat(storage): copy and move APIs (#4569)
Jordan-Nelson Mar 21, 2024
cf1cd4a
chore: update download apis to use path (#4561)
khatruong2009 Mar 25, 2024
92f7ffc
feat(storage): update `remove` and `removeMany` APIs (#4593)
Jordan-Nelson Mar 26, 2024
734c3e8
chore: remove unused types and constructors, use consistent naming (…
Jordan-Nelson Mar 27, 2024
6379d5a
feat: update list API (#4600)
khatruong2009 Mar 27, 2024
c2c0b91
chore(storage): cleanup and enable tests (#4617)
Jordan-Nelson Mar 28, 2024
d1b8f54
Update packages/storage/amplify_storage_s3/example/integration_test/u…
Jordan-Nelson Mar 28, 2024
add05b0
chore: add space back to test path
Jordan-Nelson Apr 2, 2024
f277464
chore: update path in test
Jordan-Nelson Apr 2, 2024
3ce6292
chore: clean up example app
Jordan-Nelson Apr 3, 2024
8722cad
chore: rename `withIdentityId` to `fromIdentityId`
Jordan-Nelson Apr 3, 2024
d4c7677
chore: add validation for empty path
Jordan-Nelson Apr 3, 2024
4b516c1
chore: add tests for path resolver
Jordan-Nelson Apr 3, 2024
75dcdb7
chore: remove reference to CLI in doc comment
Jordan-Nelson Apr 3, 2024
ea79fb9
chore: add comment to `StoragePathFromIdentityId`
Jordan-Nelson Apr 3, 2024
c8cc621
chore: revert public API changes in s3 list result
Jordan-Nelson Apr 4, 2024
645218d
chore: use `resolvePaths` in copy API
Jordan-Nelson Apr 4, 2024
d479236
chore: update error handling for identityId
Jordan-Nelson Apr 9, 2024
9138e1e
chore: undo changes to type cast in html download file
Jordan-Nelson Apr 9, 2024
78886e0
chore: fix failing copy tests
Jordan-Nelson Apr 9, 2024
f82ba4e
chore: update doc comment
Jordan-Nelson Apr 12, 2024
3d57990
chore: update doc comments
Jordan-Nelson Apr 12, 2024
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
14 changes: 5 additions & 9 deletions canaries/integration_test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

const data = 'hello, world';
const dataKey = 'hello';
const path = StoragePath.fromString('public/hello');
final event = AnalyticsEvent('hello');

Future<void> performUnauthenticatedActions() async {
// Upload data to Storage
await Amplify.Storage.uploadData(
data: HttpPayload.string(data),
key: dataKey,
path: path,
).result;

// Record Analytics event
Expand All @@ -63,19 +63,15 @@ void main() {
Future<void> performAuthenticatedActions() async {
// Retrieve guest data
final guestData = await Amplify.Storage.downloadData(
key: dataKey,
options: const StorageDownloadDataOptions(
accessLevel: StorageAccessLevel.guest,
),
path: path,
).result;
expect(utf8.decode(guestData.bytes), data);

// Upload data to Storage
await Amplify.Storage.uploadData(
data: HttpPayload.string(data),
key: dataKey,
options: const StorageUploadDataOptions(
accessLevel: StorageAccessLevel.private,
path: StoragePath.fromIdentityId(
(String identityId) => 'private/$identityId/hello',
),
).result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ part of 'amplify_categories.dart';
///
/// It comes with default, built-in support for Amazon S3 service
/// leveraging Amplify Auth Category for authorization.
///
/// The Amplify CLI helps you to create and configure the storage category
/// and auth category.
/// {@endtemplate}
class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
@override
Expand All @@ -37,7 +34,7 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
/// returns a [StorageListOperation].
/// {@endtemplate}
StorageListOperation list({
String? path,
required StoragePath path,
StorageListOptions? options,
}) {
return identifyCall(
Expand All @@ -50,84 +47,84 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
}

/// {@template amplify_core.amplify_storage_category.get_properties}
/// Retrieves properties of the object specified by [key] with optional
/// Retrieves properties of the object specified by [path] with optional
/// [StorageGetPropertiesOptions]. And returns a
/// [StorageGetPropertiesOperation].
///
/// The result may include the metadata (if any) specified when the object
/// was uploaded.
/// {@endtemplate}
StorageGetPropertiesOperation getProperties({
required String key,
required StoragePath path,
StorageGetPropertiesOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.getProperties,
() => defaultPlugin.getProperties(
key: key,
path: path,
options: options,
),
);
}

/// {@template amplify_core.amplify_storage_category.get_url}
/// Generates a downloadable url for the object specified by [key] with
/// Generates a downloadable url for the object specified by [path] with
/// [StorageGetUrlOptions], and returns a [StorageGetUrlOperation].
///
/// The url is presigned by the aws_signature_v4, and is enforced with scheme
/// `https`.
/// {@endtemplate}
StorageGetUrlOperation getUrl({
required String key,
required StoragePath path,
StorageGetUrlOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.getUrl,
() => defaultPlugin.getUrl(
key: key,
path: path,
options: options,
),
);
}

/// {@template amplify_core.amplify_storage_category.download_data}
/// Downloads bytes of object specified by [key] into memory with optional
/// Downloads bytes of object specified by [path] into memory with optional
/// [onProgress] and [StorageDownloadDataOptions], and returns a
/// [StorageDownloadDataOperation].
///
/// Ensure you are managing the data in memory properly to avoid unexpected
/// memory leaks.
/// {@endtemplate}
StorageDownloadDataOperation downloadData({
required String key,
required StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadDataOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.downloadData,
() => defaultPlugin.downloadData(
key: key,
path: path,
onProgress: onProgress,
options: options,
),
);
}

/// {@template amplify_core.amplify_storage_category.download_file}
/// Downloads the object specified by [key] to [localFile] with optional
/// Downloads the object specified by [path] to [localFile] with optional
/// [onProgress] and [StorageDownloadFileOptions], and returns a
/// [StorageDownloadFileOperation].
/// {@endtemplate}
StorageDownloadFileOperation downloadFile({
required String key,
required StoragePath path,
required AWSFile localFile,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadFileOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.downloadFile,
() => defaultPlugin.downloadFile(
key: key,
path: path,
localFile: localFile,
onProgress: onProgress,
options: options,
Expand All @@ -137,21 +134,21 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {

/// {@template amplify_core.amplify_storage_category.upload_data}
/// Uploads [data] as a [StorageDataPayload] with optional
/// [onProgress] and [StorageUploadDataOptions] to object specified by [key],
/// [onProgress] and [StorageUploadDataOptions] to object specified by [path],
/// and returns a [StorageUploadDataOperation].
///
/// See [StorageDataPayload] for supported data formats.
/// {@endtemplate}
StorageUploadDataOperation uploadData({
required StorageDataPayload data,
required String key,
required StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageUploadDataOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.uploadData,
() => defaultPlugin.uploadData(
key: key,
path: path,
data: data,
onProgress: onProgress,
options: options,
Expand All @@ -161,22 +158,22 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {

/// {@template amplify_core.amplify_storage_category.upload_file}
/// Uploads data from [localFile] with optional [onProgress] and
/// [StorageUploadFileOptions] to object specified by [key], and returns a
/// [StorageUploadFileOptions] to object specified by [path], and returns a
/// [StorageUploadFileOperation].
///
/// [AWSFile] provides various adapters to read file content from file
/// abstractions, such as `XFile`, `PlatformFile`, `io.File` or `html.File`.
/// {@endtemplate}
StorageUploadFileOperation uploadFile({
required AWSFile localFile,
required String key,
required StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageUploadFileOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.uploadFile,
() => defaultPlugin.uploadFile(
key: key,
path: path,
localFile: localFile,
onProgress: onProgress,
options: options,
Expand All @@ -190,12 +187,11 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
/// {@endtemplate}
///
/// {@template amplify_core.amplify_storage_category.copy_source}
/// The `source` should be readable to the API call originator following
/// corresponding [StorageAccessLevel].
/// The `source` should be readable to the API call originator.
/// {@endtemplate}
StorageCopyOperation copy({
required StorageItemWithAccessLevel<StorageItem> source,
required StorageItemWithAccessLevel<StorageItem> destination,
required StoragePath source,
required StoragePath destination,
StorageCopyOptions? options,
}) {
return identifyCall(
Expand All @@ -208,65 +204,32 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
);
}

/// {@template amplify_core.amplify_storage_category.move}
/// Moves [source] to [destination] with optional [StorageMoveOptions],
/// and returns a [StorageMoveOperation].
///
/// This API performs two consecutive S3 service calls:
/// 1. copy the source object to destination objection
/// 2. delete the source object
///
/// {@macro amplify_core.amplify_storage_category.copy_source}
/// {@endtemplate}
@Deprecated(
'This API will be removed in the next major version. '
'This API calls Amplify.Storage.copy() to create a copy of the file in the '
'destination directory and then calls Amplify.Storage.remove() to remove '
'the source file. '
'Please use Amplify.Storage.copy() and Amplify.Storage.remove() directly '
'instead.',
)
StorageMoveOperation move({
required StorageItemWithAccessLevel<StorageItem> source,
required StorageItemWithAccessLevel<StorageItem> destination,
StorageMoveOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.move,
() => defaultPlugin.move(
source: source,
destination: destination,
options: options,
),
);
}

/// {@template amplify_core.amplify_storage_category.remove}
/// Removes an object specified by [key] with optional [StorageRemoveOptions],
/// Removes an object specified by [path] with optional [StorageRemoveOptions],
/// and returns a [StorageRemoveOperation].
/// {@endtemplate}
StorageRemoveOperation remove({
required String key,
required StoragePath path,
StorageRemoveOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.remove,
() => defaultPlugin.remove(key: key, options: options),
() => defaultPlugin.remove(path: path, options: options),
);
}

/// {@template amplify_core.amplify_storage_category.remove_many}
/// Removes multiple objects specified by [keys] with optional
/// Removes multiple objects specified by [paths] with optional
/// [StorageRemoveManyOptions], and returns a [StorageRemoveManyOperation].
/// {@endtemplate}
StorageRemoveManyOperation removeMany({
required List<String> keys,
required List<StoragePath> paths,
StorageRemoveManyOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.removeMany,
() => defaultPlugin.removeMany(
keys: keys,
paths: paths,
options: options,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.list}
StorageListOperation list({
String? path,
required StoragePath path,
StorageListOptions? options,
}) {
throw UnimplementedError('list() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.get_properties}
StorageGetPropertiesOperation getProperties({
required String key,
required StoragePath path,
StorageGetPropertiesOptions? options,
}) {
throw UnimplementedError('getProperties() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.get_url}
StorageGetUrlOperation getUrl({
required String key,
required StoragePath path,
StorageGetUrlOptions? options,
}) {
throw UnimplementedError('getUrl() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.download_data}
StorageDownloadDataOperation downloadData({
required String key,
required StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadDataOptions? options,
}) {
Expand All @@ -49,7 +49,7 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.download_file}
StorageDownloadFileOperation downloadFile({
required String key,
required StoragePath path,
required AWSFile localFile,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadFileOptions? options,
Expand All @@ -59,7 +59,7 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.upload_data}
StorageUploadDataOperation uploadData({
required String key,
required StoragePath path,
required StorageDataPayload data,
void Function(StorageTransferProgress)? onProgress,
StorageUploadDataOptions? options,
Expand All @@ -69,7 +69,7 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.upload_file}
StorageUploadFileOperation uploadFile({
required String key,
required StoragePath path,
required AWSFile localFile,
void Function(StorageTransferProgress)? onProgress,
StorageUploadFileOptions? options,
Expand All @@ -79,33 +79,24 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.copy}
StorageCopyOperation copy({
required StorageItemWithAccessLevel<StorageItem> source,
required StorageItemWithAccessLevel<StorageItem> destination,
required StoragePath source,
required StoragePath destination,
StorageCopyOptions? options,
}) {
throw UnimplementedError('copy() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.move}
StorageMoveOperation move({
required StorageItemWithAccessLevel<StorageItem> source,
required StorageItemWithAccessLevel<StorageItem> destination,
StorageMoveOptions? options,
}) {
throw UnimplementedError('move() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.remove}
StorageRemoveOperation remove({
required String key,
required StoragePath path,
StorageRemoveOptions? options,
}) {
throw UnimplementedError('remove() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.remove_many}
StorageRemoveManyOperation removeMany({
required List<String> keys,
required List<StoragePath> paths,
StorageRemoveManyOptions? options,
}) {
throw UnimplementedError('removeMany() has not been implemented.');
Expand Down
Loading
Loading