readFileAsBase64 method

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

if path (entire Lunix or windows path) is provide, fileName must be null

  • returns file as base64 string or null if file do not exists

Implementation

Future<String?> readFileAsBase64({String? fileName, String? path}) async {
  File file =
      File(validatePath(path) ?? "${await filesPath}$pathJoin$fileName");
  return file.existsSync()
      ? base64Encode(
          File(validatePath(path) ?? "${await filesPath}$pathJoin$fileName")
              .readAsBytesSync())
      : null;
}