permaStoreCachedXFile function
Implementation
Future<String> permaStoreCachedXFile(XFile file, [String? _name]) async {
final basePath = await localPath;
// prefer keeping relative folder if the file already lives in our app dir
String? relativeName;
if (file.path.startsWith(basePath)) {
relativeName = file.path.substring(basePath.length + 1);
}
final name = _name ?? relativeName ?? file.name;
final target = await localFile(name);
await target.parent.create(recursive: true);
await file.saveTo(target.path);
debugPrint('Persisted cached file to ${target.path}');
return name;
}