fromFile static method
Future<bool>
fromFile(
- XFile file, {
- String? mime,
- String? name,
- SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
Copies provided file to a location where it's accessible by the user.
Returns true if the file has been saved and false if user has cancelled the action
(can happen only on Android). Throws if there's been an error.
If mime or name parameters are not provided, they will be inferred using the following methods, in order:
For mime :
XFile.mimeTypeparameterlookupMimeTypefunction i. Using magic bytes ii. Using file extension Forname:XFile.nameparameter- Last segment of
XFile.path
The extensionBehavior parameter determines what to do if the extension of provided or inferred name
does not match the provided or inferred mime type.
See SaveFileExtensionBehavior for documentation of the available options.
On native platforms, file must be accessible by the app.
On the Web, file can point to an arbitrary URL but consider using the following, more specialized APIs:
- UtopiaSaveFileWeb.fromBlob convenience method for Blobs
- fromUrl for HTTP(S) URLs
Implementation
static Future<bool> fromFile(
XFile file, {
String? mime,
String? name,
SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
}) async {
final metadata = await MetadataHelper.fromFile(file, mime: mime, name: name);
return _impl.fromFile(file, ExtensionHelper.ensureValid(metadata, extensionBehavior));
}