readFileInputElementAsBase64 function

Future<String?> readFileInputElementAsBase64(
  1. FileUploadInputElement? input,
  2. [bool removeExifFromImage = false]
)

Reads selected file of input as Base64.

Implementation

Future<String?> readFileInputElementAsBase64(FileUploadInputElement? input,
    [bool removeExifFromImage = false]) async {
  if (input == null || input.files == null || input.files!.isEmpty) return null;

  var file = input.files!.first;

  String? data;
  if (removeExifFromImage) {
    var dataURL = await removeExifFromImageFile(file);
    if (dataURL != null) {
      data = DataURLBase64.parsePayloadAsBase64(dataURL);
    }
  }
  data ??= await readFileDataAsBase64(file);

  return data;
}