I'm using the package image_picker to accept an image from the user. This results in a PickedFile and byte array. Since the image is then uploaded I'm wondering how to guess the mime type from the byte array.
PickedFile image = await _picker.getImage(source: ImageSource.gallery, imageQuality: 50); Uint8List data = await image.readAsBytes();
Solution 1: jamesdlin
(See https://github.com/dart-lang/mime/blob/master/lib/src/magic_number.dart for the current list of types it supports out of the box.)
final data = await image.readAsBytes(); final mime = lookupMimeType('', headerBytes: data);