copyToRemoteStorage method

Future<String> copyToRemoteStorage({
  1. required String fileId,
  2. required String target,
  3. bool? makePublic,
  4. FilesPatternValue? pattern,
})

Since: v0.6

POST requests are used to copy original files or their modified versions to a custom storage.

Source files MAY either be stored or just uploaded and MUST NOT be deleted.

Copying of large files is not supported at the moment. File size MUST NOT exceed 5 GB.

Implementation

Future<String> copyToRemoteStorage({
  required String fileId,
  required String target,
  bool? makePublic,

  /// The parameter is used to specify file names Uploadcare passes to a custom storage.
  /// If the parameter is omitted, your custom storages pattern is used. Use any combination of allowed values.
  ///
  /// Default: FilesPatternValue.Default
  FilesPatternValue? pattern,
}) async {
  _ensureRightVersionForCopyApi();

  final request =
      createRequest('POST', buildUri('$apiUrl/files/remote_copy/'))
        ..body = jsonEncode({
          'source': fileId,
          'target': target,
          if (makePublic != null) 'make_public': makePublic.toString(),
          if (pattern != null) 'pattern': pattern.toString(),
        });

  final response =
      (await resolveStreamedResponse(request.send())) as Map<String, dynamic>;

  return response['result'];
}