MediaItem.fromFile constructor

MediaItem.fromFile(
  1. File file,
  2. String name, {
  3. bool? spoiler,
  4. String? proxyUrl,
  5. int? height,
  6. int? width,
  7. String? contentType,
  8. String? description,
})

Implementation

factory MediaItem.fromFile(
  File file,
  String name, {
  bool? spoiler,
  String? proxyUrl,
  int? height,
  int? width,
  String? contentType,
  String? description,
}) {
  if (!file.existsSync()) {
    throw ArgumentError('File ${file.path} does not exist');
  }

  if (name.isEmpty) {
    throw ArgumentError("Name can't be empty.");
  }

  final bytes = file.readAsBytesSync();

  return MediaItem._(
    'attachment://$name',
    spoiler: spoiler,
    proxyUrl: proxyUrl,
    height: height,
    width: width,
    contentType: contentType,
    description: description,
  )..bytes = bytes;
}