【问题标题】:How to load image into memory and then save to Firebase Storage in Flutter / Dart如何将图像加载到内存中,然后在 Flutter / Dart 中保存到 Firebase 存储
【发布时间】:2020-10-20 02:30:07
【问题描述】:

我将照片从 URL 加载到内存中(使用 http 包中的“get”方法),然后尝试将其保存为 Firebase 存储中的文件。

这是我正在使用的代码:

response = await http.get(photoUrl);
file = File.fromRawPath(response.bodyBytes);
FirebaseStorage.instance.ref().child(path).putFile(file);           

我收到以下错误:

错误:'package:firebase_storage/src/storage_reference.dart':断言失败:第 62 行 pos 12:'file.existsSync()':不正确。

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: firebase flutter dart firebase-storage


    【解决方案1】:

    由于您将照片的内容读入内存,它不是文件,“没有任何意义。

    要从内存上传原始数据,您应该使用StorageReference.putData method

    类似:

    response = await http.get(photoUrl);
    var bytes = response.bodyBytes;
    FirebaseStorage.instance.ref().child(path).putData(bytes);
    

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 2019-07-24
      • 2021-03-14
      • 1970-01-01
      • 2021-10-14
      • 2011-07-19
      • 2021-03-19
      • 2014-06-01
      • 2019-09-22
      相关资源
      最近更新 更多