如何解决Flutter网站:firebase_storage:MissingPluginException找不到方法StorageReference#putData的实现
我正在尝试将UInt8List格式的图像上传到Firebase存储。我正在使用“ StorageReference.putData”。我不断收到此错误消息,指出未定义putFile。我已经更新了所有相关的firebase软件包,但仍然没有成功。在Flutter Web上不能使用putData吗?
我尝试过更新所有软件包,然后“干净清除”,“获取干净的软件包”
我之所以不使用“ putFile”,是因为Flutter Web不支持dart:io,后者保存了使用putFile所需的特定File类。
错误:
Error: MissingPluginException(No implementation found for method StorageReference#putData on channel plugins.flutter.io/firebase_storage)
at Object.throw_ [as throw] (http://localhost:60357/dart_sdk.js:4331:11)
at MethodChannel._invokeMethod (http://localhost:60357/packages/flutter/src/services/system_channels.dart.lib.js:942:21)
at _invokeMethod.next (<anonymous>)
at http://localhost:60357/dart_sdk.js:37593:33
at _RootZone.runUnary (http://localhost:60357/dart_sdk.js:37447:58)
at _FutureListener.thenAwait.handleValue (http://localhost:60357/dart_sdk.js:32424:29)
at handleValueCallback (http://localhost:60357/dart_sdk.js:32971:49)
at Function._propagateToListeners (http://localhost:60357/dart_sdk.js:33009:17)
at _Future.new.[_completeWithValue] (http://localhost:60357/dart_sdk.js:32852:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:60357/dart_sdk.js:32874:35)
at Object._microtaskLoop (http://localhost:60357/dart_sdk.js:37708:13)
at _startMicrotaskLoop (http://localhost:60357/dart_sdk.js:37714:13)
at http://localhost:60357/dart_sdk.js:33226:9
我的上传功能:
Future<StorageTaskSnapshot> uploadImage(Uint8List imageFile,int pos) {
return storageRef
.child("posts/${currentUser.uid}/$_postId/$pos.jpg")
.putData(imageFile)
.onComplete;
}
解决方法
在混合了其他几个人的答案之后,我终于使这个工作了。我从image_picker_for_web中的图片开始:
mysql
然后:
final picker = ImagePicker();
final new_image = await picker.getImage(
source: source=='gallery' ? ImageSource.gallery : ImageSource.camera,);
这是向我指明正确方向的SO:Flutter Web Upload to Firestore
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。