readFileToBase64Str function
从文件路径获取文件base64字符串
Implementation
Future<String> readFileToBase64Str(String path, {String? defaultStr}) async {
File file = File(path);
if (!await file.exists()) {
"文件不存在:$path".logE();
if (isEmptyOrNull(defaultStr)) {
throw Exception('文件不存在');
} else {
return defaultStr!;
}
}
String res = base64Encode(await file.readAsBytes());
"$path base64Encode length: ${res.length}".logI();
return res;
}