importFile static method
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);
}