parseFileToBase64 function
parseFileToBase64 is a helper function to parse a file to base64. Will return a Map with the keys:
'base64'- the base64 string of the file.'name'- the name of the file.'mimeType'- the mime type of the file. And, will receive afileargument that should be aPlatformFileinstance.
Implementation
Future<Map<String, String>?> parseFileToBase64(ThemedFile file) async {
List<int> byteArray = file.bytes.toList();
String? mimeType = file.mimeType;
if (mimeType != null) {
return {
'name': file.name,
'mimeType': mimeType,
'base64': base64Encode(byteArray),
};
}
return null;
}