是否有使用Flutter Web将文件上传到服务器的插件或方法? [英] Is there any plugin or way to upload file to server using flutter web?

查看:642
本文介绍了是否有使用Flutter Web将文件上传到服务器的插件或方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像从Flutter Web应用程序上传到服务器.有没有更好的方法可以做到这一点.

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

我已经尝试了几个插件. 图像选择器,文件选择器 但是Flutter网站不支持它们.

I've already tried with couple of plugins. image-picker, file-picker But none of them are supported for flutter web.

推荐答案

您可以使用dart:html的FileUploadInputElement类.

you can use the FileUploadInputElement class of dart:html.

要做的第一件事是导入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);
  }
});
}

这篇关于是否有使用Flutter Web将文件上传到服务器的插件或方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆