fromFile static method

Future<bool> fromFile(
  1. XFile file, {
  2. String? mime,
  3. String? name,
  4. 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 :

  1. XFile.mimeType parameter
  2. lookupMimeType function i. Using magic bytes ii. Using file extension For name :
  3. XFile.name parameter
  4. 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:

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));
}