gpt4 book ai didi

firebase-storage - 颤振网络 : firebase_storage: MissingPluginException No implementation found for method StorageReference#putData

转载 作者:行者123 更新时间:2023-12-04 08:59:59 27 4
gpt4 key购买 nike

我正在尝试将 UInt8List 格式的图像上传到 firebase 存储。我正在使用“StorageReference.putData”。我不断收到此错误消息,指出未定义 putFile。我已经更新到所有迟到的 firebase 包,但仍然没有成功。难道在 Flutter Web 上不能使用 putData 吗?

我尝试更新所有包,然后“flutter clean”、“flutter packages get”

我不使用“putFile”的原因是因为 Flutter Web 不支持 dart:io,它包含使用 putFile 所需的特定文件类。

错误:

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 中的图像开始:

final picker = ImagePicker();
final new_image = await picker.getImage(
source: source=='gallery' ? ImageSource.gallery : ImageSource.camera,
);

然后:

String url;
var bytes = await new_image.readAsBytes();
try {
fb.StorageReference _storage = fb.storage().ref('002test');
fb.UploadTaskSnapshot uploadTaskSnapshot = await _storage.put(bytes, fb.UploadMetadata(contentType: 'image/png')).future;
var imageUri = await uploadTaskSnapshot.ref.getDownloadURL();
url = imageUri.toString();
} catch (e) {
print(e);
}

这是为我指明正确方向的 SO:Flutter Web Upload to Firestore

关于firebase-storage - 颤振网络 : firebase_storage: MissingPluginException No implementation found for method StorageReference#putData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63604931/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com