-
Notifications
You must be signed in to change notification settings - Fork 238
/
amplify_storage_category.dart
241 lines (227 loc) · 7.44 KB
/
amplify_storage_category.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
part of 'amplify_categories.dart';
/// {@template amplify_core.amplify_storage_category}
/// The Amplify Storage category provides an interface for interacting with
/// a storage plugin.
///
/// 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
@nonVirtual
Category get category => Category.storage;
@override
@nonVirtual
Set<Category> get categoryDependencies => const {Category.auth};
P getPlugin<P extends StoragePluginInterface>(
StoragePluginKey<P> pluginKey,
) =>
plugins.singleWhere(
(p) => p is P,
orElse: () => throw PluginError(
'No plugin registered for $pluginKey',
),
) as P;
/// {@template amplify_core.amplify_storage_category.list}
/// Lists objects under the [path] with optional [StorageListOptions] and
/// returns a [StorageListOperation].
/// {@endtemplate}
StorageListOperation list({
String? path,
StorageListOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.list,
() => defaultPlugin.list(
path: path,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.get_properties}
/// 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 StoragePath path,
StorageGetPropertiesOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.getProperties,
() => defaultPlugin.getProperties(
path: path,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.get_url}
/// 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 StoragePath path,
StorageGetUrlOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.getUrl,
() => defaultPlugin.getUrl(
path: path,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.download_data}
/// 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 StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadDataOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.downloadData,
() => defaultPlugin.downloadData(
path: path,
onProgress: onProgress,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.download_file}
/// Downloads the object specified by [path] to [localFile] with optional
/// [onProgress] and [StorageDownloadFileOptions], and returns a
/// [StorageDownloadFileOperation].
/// {@endtemplate}
StorageDownloadFileOperation downloadFile({
required StoragePath path,
required AWSFile localFile,
void Function(StorageTransferProgress)? onProgress,
StorageDownloadFileOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.downloadFile,
() => defaultPlugin.downloadFile(
path: path,
localFile: localFile,
onProgress: onProgress,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.upload_data}
/// Uploads [data] as a [StorageDataPayload] with optional
/// [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 StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageUploadDataOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.uploadData,
() => defaultPlugin.uploadData(
path: path,
data: data,
onProgress: onProgress,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.upload_file}
/// Uploads data from [localFile] with optional [onProgress] and
/// [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 StoragePath path,
void Function(StorageTransferProgress)? onProgress,
StorageUploadFileOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.uploadFile,
() => defaultPlugin.uploadFile(
path: path,
localFile: localFile,
onProgress: onProgress,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.copy}
/// Makes a copy of the [source] to [destination] with optional
/// [StorageCopyOptions], and returns a [StorageCopyOperation].
/// {@endtemplate}
///
/// {@template amplify_core.amplify_storage_category.copy_source}
/// The `source` should be readable to the API call originator following
/// corresponding [StorageAccessLevel].
/// {@endtemplate}
StorageCopyOperation copy({
required StoragePath source,
required StoragePath destination,
StorageCopyOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.copy,
() => defaultPlugin.copy(
source: source,
destination: destination,
options: options,
),
);
}
/// {@template amplify_core.amplify_storage_category.remove}
/// Removes an object specified by [key] with optional [StorageRemoveOptions],
/// and returns a [StorageRemoveOperation].
/// {@endtemplate}
StorageRemoveOperation remove({
required String key,
StorageRemoveOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.remove,
() => defaultPlugin.remove(key: key, options: options),
);
}
/// {@template amplify_core.amplify_storage_category.remove_many}
/// Removes multiple objects specified by [keys] with optional
/// [StorageRemoveManyOptions], and returns a [StorageRemoveManyOperation].
/// {@endtemplate}
StorageRemoveManyOperation removeMany({
required List<String> keys,
StorageRemoveManyOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.removeMany,
() => defaultPlugin.removeMany(
keys: keys,
options: options,
),
);
}
}