Flutter网站:firebase_storage:MissingPluginException找不到方法StorageReference#putData的实现 [英] Flutter Web: firebase_storage: MissingPluginException No implementation found for method StorageReference#putData

查看:104
本文介绍了Flutter网站:firebase_storage:MissingPluginException找不到方法StorageReference#putData的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to upload an image in UInt8List format to firebase storage. I am using "StorageReference.putData". I keep getting this error saying that putFile isn't defined. I have updated to all the lated firebase packages and still no success. Is putData not possible on Flutter Web?

我尝试过更新所有软件包,然后干净清除",获取干净的软件包"

I have tried to update all packages and then 'flutter clean', 'flutter packages get'

我不使用"putFile"的原因;是因为Flutter Web不支持dart:io,该dart:io拥有使用putFile所需的特定File类.

The reason I am not using "putFile" is because Flutter Web doesn't support dart:io which holds the specific File class required for using 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中的图片开始:

I finally got this to work after hybridizing several other people's answers. I start with an image from 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);
}

这是向我指明正确方向的方法: Flutter Web上传到Firestore

This was the SO that pointed me in the right direction: Flutter Web Upload to Firestore

这篇关于Flutter网站:firebase_storage:MissingPluginException找不到方法StorageReference#putData的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆