Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter-web

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.

like image 795
Deeptha Senanayake Avatar asked Jun 05 '19 08:06

Deeptha Senanayake


1 Answers

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);
  }
});
}
like image 103
basedgod Avatar answered Oct 04 '22 00:10

basedgod