prepare static method
Turns picked bytes into an UploadSource: resolves the MIME type from the name when missing, converts HEIC/HEIF to JPEG and shrinks big photos.
Implementation
static Future<UploadSource> prepare(List<int> bytes, String name, String? mimeType) async {
final mime = (mimeType == null || mimeType.isEmpty || mimeType == 'application/octet-stream')
? (mimeTypeForName(name) ?? 'application/octet-stream')
: mimeType.toLowerCase();
final heic = mime == 'image/heic' || mime == 'image/heif';
final big = (mime == 'image/jpeg' || mime == 'image/webp') && bytes.length > recompressAbove;
if (!heic && !big) return UploadSource(bytes: bytes, name: name, mimeType: mime);
final out = await encodeJpeg(bytes, maxSide: maxImageSide, quality: jpegQuality);
// No encoder on this platform: send the original (the gateway accepts HEIC).
if (out == null) return UploadSource(bytes: bytes, name: name, mimeType: mime);
return UploadSource(bytes: out, name: _withExtension(name, 'jpg'), mimeType: 'image/jpeg');
}