fromAsset static method

Future<bool> fromAsset(
  1. String key, {
  2. String? mime,
  3. String? name,
  4. SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
})

Copies asset at key 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: For mime: lookupMimeType function (using file extension). For name: Last segment of key.

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 the Web, method will complete immediately and start the download in the background, without the ability to monitor its status. To gain more control over this process, consider using HttpRequest.request with responseType: 'blob' and then UtopiaSaveFileWeb.fromBlob.

Implementation

static Future<bool> fromAsset(
  String key, {
  String? mime,
  String? name,
  SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
}) async {
  final metadata = await MetadataHelper.fromAsset(key, mime: mime, name: name);
  return _impl.fromAsset(key, ExtensionHelper.ensureValid(metadata, extensionBehavior));
}