importFile static method

Future<void> importFile(
  1. String sourcePath,
  2. String key, {
  3. UStorageBucket bucket = UStorageBucket.support,
  4. bool deleteSource = false,
  5. String? mimeType,
  6. Map<String, String>? tags,
})

Copies (or moves) a file from anywhere on disk into storage. Encrypts it for the vault.

Implementation

static Future<void> importFile(
  String sourcePath,
  String key, {
  UStorageBucket bucket = UStorageBucket.support,
  bool deleteSource = false,
  String? mimeType,
  Map<String, String>? tags,
}) async {
  if (!_backend.hasFileSystem) throw UnsupportedError("importFile needs a file system; use write() on the web.");
  await _ensure();
  if (bucket == UStorageBucket.vault) {
    await write(key, _backend.read(sourcePath), bucket: bucket, mimeType: mimeType, tags: tags);
    if (deleteSource) await _backend.delete(sourcePath);
    return;
  }
  final String path = _pathFor(bucket, key);
  if (deleteSource) {
    await _backend.move(sourcePath, path);
  } else {
    await _backend.copy(sourcePath, path);
  }
  await _record(key, bucket, await _backend.length(path) ?? 0, mimeType: mimeType, tags: tags);
}