fromBytes static method

Future<bool> fromBytes(
  1. List<int> bytes, {
  2. required String mime,
  3. required String name,
  4. SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
})

Saves provided bytes to file in a location 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.

Both mime and name parameters must be provided. To allow for automatic inference, use fromFile or fromUrl methods.

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.

For bigger files, consider using a streaming approach with fromByteStream to avoid loading the whole file to memory.

Implementation

static Future<bool> fromBytes(
  List<int> bytes, {
  required String mime,
  required String name,
  SaveFileExtensionBehavior extensionBehavior = SaveFileExtensionBehavior.replace,
}) async {
  final metadata = SaveFileMetadata(object: '<raw bytes>', name: name, mime: mime);
  return _impl.fromBytes(bytes, ExtensionHelper.ensureValid(metadata, extensionBehavior));
}