File input and Dart

前端 未结 5 576
余生分开走
余生分开走 2020-12-11 03:14

I\'m trying out Dart, but I cant figure out, how to send an image from the user to the server. I have my input-tag, and i can reach this in the DART code, but i cant seem to

5条回答
  •  Happy的楠姐
    2020-12-11 03:57

    My attempt

      void fileSelected(Event event) async {
        final files = (event.target as FileUploadInputElement).files;
        if (files.isNotEmpty) {
          final reader = new FileReader();
    
          // ignore: unawaited_futures
          reader.onError.first.then((evt) => print('error ${reader.error.code}'));
          final resultReceived = reader.onLoad.first;
          reader.readAsArrayBuffer(files.first);
    
          await resultReceived;
          imageReference.fileSelected(reader.result as List);
        }
      }
    

提交回复
热议问题