readDroppedImageAttachment function

Future<PromptAttachment?> readDroppedImageAttachment(
  1. PromptAttachment attachment
)

Implementation

Future<PromptAttachment?> readDroppedImageAttachment(
  PromptAttachment attachment,
) async {
  final file = File(attachment.path);
  final Uint8List bytes;
  try {
    bytes = await readBoundedFileSnapshot(file, maxBytes: 4 * 1024 * 1024);
  } on BoundedFileSnapshotOverflowException {
    throw const FileSystemException('Images must be 4 MB or smaller.');
  }
  if (bytes.isEmpty) {
    throw const FileSystemException('Images must be 4 MB or smaller.');
  }
  return PromptAttachment.fromBytes(
    bytes: bytes,
    name: attachment.name,
    mimeType: attachment.imageMimeType ?? 'image/png',
  );
}