我试图为 Flutter 中的项目创建一个简单的文件上传器,旨在将图像上传到 Firebase 存储桶,但我找不到选择文件类型的方法。
我已经阅读了Dart的不那么详尽的文档,但我没有找到与我想要做的类似的东西。
static Future<Uri> showUploadDialog(
firebase.StorageReference filePath, String fileName) async {
Completer completer = Completer();
InputElement uploadInput = FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen(
(changeEvent) {
final file = uploadInput.files.first;
final reader = FileReader();
reader.onLoadEnd.listen(
(loadEndEvent) async {
debugPrint("Selected the file to be uploaded.");
// Here we handle the file.
completer.complete(uploadFile(file, filePath, fileName));
},
);
reader.readAsDataUrl(file);
},
);
return await completer.future;
}
Run Code Online (Sandbox Code Playgroud)
我的目标是能够看到一个 FileUploadInputElement,它不允许我上传与图像文件不同的文件(具有图像特定的扩展名)。