uploadBinary method
Future<String>
uploadBinary(
- String path,
- Uint8List data, {
- FileOptions fileOptions = const FileOptions(),
- int? retryAttempts,
- StorageRetryController? retryController,
Uploads a binary file to an existing bucket. Can be used on the web.
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.
data
is the binary file data 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> uploadBinary(
String path,
Uint8List data, {
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.postBinaryFile(
'$url/object/$finalPath',
data,
fileOptions,
options: FetchOptions(headers: headers),
retryAttempts: retryAttempts ?? _retryAttempts,
retryController: retryController,
);
return (response as Map)['Key'] as String;
}