loadFile method

dynamic loadFile(
  1. dynamic formname,
  2. dynamic item,
  3. dynamic id,
  4. dynamic context,
)

Implementation

loadFile(formname, item, id, context) async {
  myLogAll('loadFile');
  if (isNull(formname)) {
    return;
  }

  removeOverlay();

  FilePickerResult? result = await pickFiles();
  if (result == null || result.files.isEmpty) {
    throw Exception('Cannot read file from null stream');
  }
  var file = result.files.first;
  //var filePath = file.path;
  var filename = file.name;
  final fileReadStream = file.readStream;
  if (fileReadStream == null) {
    throw Exception('Cannot read file from null stream');
  }
  if (file.size > 1048576) {
    throw Exception('file size can not be over 1M');
  }
  final stream = http.ByteStream(fileReadStream);

  uploadToServer(context, filename, stream, file.size, formname, item, id);
}