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

南楼画角 提交于 2019-12-07 03:29:03

问题


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, file-picker But none of them are supported for flutter web.


回答1:


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);
  }
});
}


来源:https://stackoverflow.com/questions/56457214/is-there-any-plugin-or-way-to-upload-file-to-server-using-flutter-web

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!