fromFile static method
Creates a data part from an XFile.
Implementation
static Future<DataPart> fromFile(XFile file) async {
final Uint8List bytes = await file.readAsBytes();
final String? name = _nameFromPath(file.path) ?? _emptyNull(file.name);
final String mimeType =
_emptyNull(file.mimeType) ??
mimeTypeForFile(
name ?? '',
headerBytes: Uint8List.fromList(
bytes.take(defaultMagicNumbersMaxLength).toList(),
),
);
return DataPart(bytes, mimeType: mimeType, name: name);
}