Is there any plugin or way to upload file to server using flutter web?

前端 未结 1 542
遥遥无期
遥遥无期 2021-01-02 00:43

I want to upload image to the server from flutter web application. Is there any better way of doing that.

I\'ve already tried with couple of plugins. image-picker,

相关标签:
1条回答
  • 2021-01-02 01:05

    you can use the FileUploadInputElement class of dart:html.

    The first thing to do is to import dart:html.

    import 'dart:html';
    

    Implement following code to start a file picker:

    _startFilePicker() async {
    InputElement uploadInput = FileUploadInputElement();
    uploadInput.click();
    
    uploadInput.onChange.listen((e) {
      // read file content as dataURL
      final files = uploadInput.files;
      if (files.length == 1) {
        final file = files[0];
        final reader = new FileReader();
    
        reader.onLoadEnd.listen((e) {
          _handleResult(reader.result);
        });
        reader.readAsDataUrl(file);
      }
    });
    }
    
    0 讨论(0)
提交回复
热议问题