预期为“JavaScriptObject”类型的值,但在使用 getData() 方法时得到了“ClientException”类型的值

问题描述 投票:0回答:1

我正在尝试使用 Firebase 存储来存储聊天期间发生的图像数据。 当我使用 putData 保存图像数据时,它工作成功。我还检查了图像数据已保存在 Firebase 存储控制台中。

void sendImage() async {
    final chatKey = createChatKey(widget.userUid!);
    final storageRef = FirebaseStorage.instance.ref().child('chatImages/${widget.chatRoomUid}/$chatKey');
    await storageRef.putData(imageData!);
    //...
  }

但是当我尝试使用 getData() 方法读取图像数据时,出现错误。

错误:需要“JavaScriptObject”类型的值,但得到“ClientException”类型之一

这是我的阅读方法。

  void setImageData(String chatKey) async {
    final imageRef = storageRef.child('chatImages/$chatRoomUid/$chatKey');
    print(imageRef);
    imageData = await imageRef.getData();
    setState(() {
      imageData = imageData;
    });
  }

imageRef 输出如下,看起来是正常输出。

参考(应用程序:[默认],完整路径:chatImages/20240324001EblwJscB1yNb7RWsedJDpB06ddG3/2024-04-08-18:46:05-889-EblwJscB1yNb7RWsedJDpB06ddG3)`

这是我的依赖项。

  cupertino_icons: ^1.0.2
  firebase_core: ^2.27.0
  firebase_auth: ^4.17.8
  firebase_database: ^10.4.9
  provider: ^6.1.2
  table_calendar: ^3.1.0
  firebase_storage: ^11.6.9
  image_picker: ^1.0.7
  image_picker_web: ^3.1.1
  flutter_launcher_icons: ^0.13.1
flutter firebase firebase-storage
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.