问题
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