uploadBinaryToSignedUrl method

Future<String> uploadBinaryToSignedUrl(
  1. String path,
  2. String token,
  3. Uint8List data, [
  4. FileOptions fileOptions = const FileOptions(),
  5. int? retryAttempts,
  6. StorageRetryController? retryController,
])

Upload a binary file with a token generated from createUploadSignedUrl.

path The file path, including the file name. Should be of the format folder/subfolder/filename.png. The bucket must already exist before attempting to upload.

token The token generated from createUploadSignedUrl

data The body of the binary file to be stored in the bucket.

Implementation

Future<String> uploadBinaryToSignedUrl(
  String path,
  String token,
  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 cleanPath = _removeEmptyFolders(path);
  final path0 = _getFinalPath(cleanPath);
  var url = Uri.parse('${this.url}/object/upload/sign/$path0');
  url = url.replace(queryParameters: {'token': token});

  await _storageFetch.putBinaryFile(
    url.toString(),
    data,
    fileOptions,
    retryAttempts: retryAttempts ?? _retryAttempts,
    retryController: retryController,
  );

  return cleanPath;
}