upload method
Future<String>
upload(
- String path,
- File file, {
- FileOptions fileOptions = const FileOptions(),
- int? retryAttempts,
- StorageRetryController? retryController,
Uploads a file to an existing bucket.
path is the relative file path without the bucket ID. Should be of the
format folder/subfolder/filename.png. The bucket must already
exist before attempting to upload.
file is the File object to be stored in the bucket.
fileOptions HTTP headers. For example cacheControl
retryAttempts overrides the retryAttempts parameter set across the storage client.
You can pass a retryController and call cancel() to cancel the retry attempts.
Implementation
Future<String> upload(
String path,
File file, {
FileOptions fileOptions = const FileOptions(),
int? retryAttempts,
StorageRetryController? retryController,
}) async {
assert(retryAttempts == null || retryAttempts >= 0,
'retryAttempts has to be greater or equal to 0');
final finalPath = _getFinalPath(path);
final response = await storageFetch.postFile(
'$url/object/$finalPath',
file,
fileOptions,
options: FetchOptions(headers: headers),
retryAttempts: retryAttempts ?? _retryAttempts,
retryController: retryController,
);
return (response as Map)['Key'] as String;
}