imageFileToBase64 static method

Future<String> imageFileToBase64(
  1. String imagePath
)

Implementation

static Future<String> imageFileToBase64(String imagePath) async {
  String base64Image = '';


if(kIsWeb) {
//   if (imagePath.toString() != ""){
//     log("IronMap ${imagePath}");
//   html.HttpRequest request = await html.HttpRequest.request(
//       imagePath, responseType: 'blob');
//   html.Blob blob = request.response;
//
//
//   // Read the Blob data as an ArrayBuffer
//   html.FileReader reader = html.FileReader();
//   reader.readAsArrayBuffer(blob);
//
//   // Wait for the reader to load
//   await reader.onLoad.first;
//
//   // Convert the ArrayBuffer to Uint8List
//   Uint8List data = Uint8List.fromList(reader.result as List<int>);
//   base64Image = base64Encode(data);
// }
}else{
try {
  // Read the image file as bytes
  File imageFile = File(imagePath);
  if (!imageFile.existsSync()) {
    return base64Image;
  }
  List<int> imageBytes = await imageFile.readAsBytes();
  base64Image = base64Encode(imageBytes);
} catch (e) {}

}


  return base64Image;
}