uploadToSignedUrl method

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

Upload a 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

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

Implementation

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

  await _storageFetch.putFile(
    url.toString(),
    file,
    fileOptions,
    retryAttempts: retryAttempts ?? _retryAttempts,
    retryController: retryController,
  );

  return cleanPath;
}