【问题标题】:Unhandled Exception: 'package:firebase_storage/src/storage_reference.dart': Failed assertion: line 62 pos 12: 'file.existsSync()': is not true未处理的异常:'package:firebase_storage/src/storage_reference.dart':断言失败:第 62 行 pos 12:'file.existsSync()':不正确
【发布时间】:2020-09-14 15:51:57
【问题描述】:

未处理的异常:'package:firebase_storage/src/storage_reference.dart':断言失败:第 62 行 pos 12:'file.existsSync()':不正确。

在导航时,'package:firebase_storage/src/storage_reference.dart' 中的代码是:

  assert(file.existsSync());
  final _StorageFileUploadTask task =
      _StorageFileUploadTask._(file, _firebaseStorage, this, metadata);
  task._start();
  return task;
}

上传图片到firebase存储的代码:

void _selectImage(Future<File> pickImage, int imageNumber) async {
    File tempImg = await pickImage;
    switch (imageNumber) {
      case 1:
        setState(() => _image1 = tempImg);
        break;
      case 2:
        setState(() => _image2 = tempImg);
        break;
      case 3:
        setState(() => _image3 = tempImg);
        break;
      case 4:
        setState(() => _image4 = tempImg);
        break;
    }
  }

  Widget _displayChild1() {
    if (_image1 == null) {
      return Padding(
        padding: const EdgeInsets.fromLTRB(14, 70, 14, 70),
        child: new Icon(
          Icons.add,
          color: Colors.grey.withOpacity(1),
        ),
      );
    } else {
      return Image.file(
        _image1,
        fit: BoxFit.fill,
        width: double.infinity,
      );
    }
  }
 String imageUrl1;
        String imageUrl2;
        String imageUrl3;
        String imageUrl4;
        //  String imageUrl3;
        final FirebaseStorage storage = FirebaseStorage.instance;
        final String picture1 = "1${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task1 = storage.ref().child(picture1).putFile(_image1);
        final String picture2 = "2${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task2 = storage.ref().child(picture2).putFile(_image2);
        final String picture3 = "3${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task3 = storage.ref().child(picture3).putFile(_image3);
        final String picture4 = "4${DateTime.now().millisecondsSinceEpoch.toString()}.jpg";
        StorageUploadTask task4 = storage.ref().child(picture4).putFile(_image4);


        StorageTaskSnapshot snapshot1 =
        await task1.onComplete.then((sanapshot) => sanapshot);
        StorageTaskSnapshot snapshot2 =
        await task2.onComplete.then((sanapshot) => sanapshot);
        StorageTaskSnapshot snapshot3 =
        await task3.onComplete.then((sanapshot) => sanapshot);


        task4.onComplete.then((snapshot4) async {
          imageUrl1 = await snapshot1.ref.getDownloadURL();
          imageUrl2 = await snapshot2.ref.getDownloadURL();
          imageUrl3 = await snapshot3.ref.getDownloadURL();
          imageUrl4 = await snapshot4.ref.getDownloadURL();

          uploadProduct(
            images: imageUrl1,
            images2: imageUrl2,
            images3: imageUrl3,
            images4: imageUrl4,
          );


在将图像上传到 Firebase 存储之前发生错误。 有什么解决办法吗?

售价:2 美元(贝宝)

【问题讨论】:

  • 该错误表示该文件不存在,您检查它是否存在吗?您从图库应用中获取图片?
  • 是的,来自画廊。直到今天早上它都工作得很好,现在它糟透了!
  • 从画廊中挑选的临时图片也显示出来了,但没有上传
  • 你可以给超过 2 美元,但是银行转账,因为这里禁止使用 paypal :(
  • 现在由我解决!很高兴认识你.....lol lol

标签: firebase flutter firebase-storage


【解决方案1】:

这可能是flutter clean的问题,或者我只是删除了应用程序并重新安装了它:) 希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 2020-04-22
    • 2020-12-29
    • 2021-11-02
    • 2021-05-30
    相关资源
    最近更新 更多