readFileAsBase64 method

Future<String?> readFileAsBase64({
  1. String? fileName,
  2. String? path,
})

Reads the file and returns its content encoded as a Base64 string. Returns null when the file does not exist.

Implementation

Future<String?> readFileAsBase64({String? fileName, String? path}) async {
  final String resolved = await _resolvePath(fileName, path);
  final File file = File(resolved);
  if (!file.existsSync()) return null;
  return base64Encode(file.readAsBytesSync());
}