import 'dart:async';
import 'dart:html';
import 'package:mime/mime.dart' as mime;
Future<String?> getMimeType(File file) async {
// Create a slice for the header.
final slice = file.slice(0, mime.defaultMagicNumbersMaxLength);
// Read the file header's contents.
final fileReader = FileReader();
fileReader.readAsArrayBuffer(slice);
await fileReader.onLoad.first;
final header = fileReader.result as List<int>;
// Empty string for the file name because it's not relevant.
return mime.lookupMimeType('', headerBytes: header);
}
1条答案
按热度按时间1szpjjfi1#
您可以使用the mime package's函数
lookupMimeType
,并通过使用defaultMagicNumbersMaxLength
在File
上调用slice
来传入headerBytes