【发布时间】:2020-12-15 16:25:56
【问题描述】:
我正在尝试将 UInt8List 格式的图像上传到 Firebase 存储。我正在使用“StorageReference.putData”。我不断收到这个错误,说 putFile 没有定义。我已经更新了所有最新的 firebase 软件包,但仍然没有成功。在 Flutter Web 上不能 putData 吗?
我尝试更新所有包,然后'flutter clean','flutter packages get'
我不使用“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;
}
【问题讨论】:
-
cloud_firestore 插件似乎还不支持flutter web。我会寻找替代方案。 firebase_dart 插件可能会起作用。
-
你有什么运气吗?我尝试了putData,也尝试了使用文件包提供的内存文件系统的putFile,但都没有。
-
是的。我的解决方案有点混乱。检查下面的一个干净的答案,同样的想法。
标签: firebase-storage flutter-web