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