copyToLocalStorage method

Future<FileInfoEntity> copyToLocalStorage(
  1. String fileId, {
  2. bool? store,
  3. Map<String, String>? metadata,
})

Since v0.6

POST requests are used to copy original files or their modified versions to a default 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. If the file CDN URL includes transformation operators, its size MUST NOT exceed 100 MB. If not, the size MUST NOT exceed 5 GB.

Implementation

Future<FileInfoEntity> copyToLocalStorage(
  String fileId, {
  /// The parameter only applies to the Uploadcare storage and MUST be either true or false.
  ///
  /// Default: false
  bool? store,

  /// **Since v0.7**
  ///
  /// Arbitrary additional metadata.
  Map<String, String>? metadata,
}) async {
  _ensureRightVersionForCopyApi();
  if (metadata != null) _ensureRightVersionForMetadataApi();

  final request = createRequest('POST', buildUri('$apiUrl/files/local_copy/'))
    ..body = jsonEncode({
      'source': fileId,
      if (store != null) 'store': store.toString(),
      if (metadata != null) 'metadata': metadata,
    });

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

  return FileInfoEntity.fromJson(response['result']);
}