updateBinary method

Future<String> updateBinary(
  1. String path,
  2. Uint8List data, {
  3. FileOptions fileOptions = const FileOptions(),
  4. int? retryAttempts,
  5. StorageRetryController? retryController,
})

Replaces an existing file at the specified path with a new one. 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> updateBinary(
  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.putBinaryFile(
    '$url/object/$finalPath',
    data,
    fileOptions,
    options: FetchOptions(headers: headers),
    retryAttempts: retryAttempts ?? _retryAttempts,
    retryController: retryController,
  );

  return (response as Map)['Key'] as String;
}