【问题标题】:Firebase Storage error : Invalid argument: Instance of '_File'Firebase 存储错误:参数无效:“_File”实例
【发布时间】:2021-03-09 10:24:37
【问题描述】:

我正在尝试将图像上传到 Firebase 存储,但尝试上传时出现此错误:

  Invalid argument: Instance of '_File'

这是通过图像选择器获取的文件的调试控制台打印,我不确定我哪里出错了:

I/flutter (21742): File: '/data/user/0/com.example.weepay_pos/cache/image_picker175751972.jpg'

这是我的代码:

Future getImage() async {


    final pickedFile = await picker.getImage(source: ImageSource.gallery);

    setState(() {
        if (pickedFile != null) {
            _imageFile = File(pickedFile.path);
            print(_imageFile);
        } else {
            print('No image selected.');
        }
    });
}
Future upload() async {

    FirebaseStorage storage = FirebaseStorage.instance;
    Reference ref = storage.ref().child("$_imageFile" + DateTime.now().toString());
    UploadTask uploadTask = ref.putFile(_imageFile);
    uploadTask.then((res) {


        print("Image Uploaded");
    });

}

【问题讨论】:

  • 不确定您是否使用变量 _File 但也许this 可以帮助您

标签: android firebase flutter dart firebase-storage


【解决方案1】:

你需要在这里定义一个字符串变量。它是 File 的一个实例。

Reference ref = storage.ref().child("imageFileName" + DateTime.now().toString());

【讨论】:

  • 很抱歉没有关注你
  • 请你解释一下
  • 在这里您尝试使用文件实例:"$_imageFile" 但它需要一个字符串变量。所以,你不应该使用那个变量。您可以在此处键入任何字符串值。
  • 我把它改成了一个字符串,只是一些随机数,我也犯了同样的错误
  • 它甚至说这是异常“/data/user/0/com.example.weepay_pos/cache/image_picker1937673433.jpg”中的无效值
猜你喜欢
  • 2016-12-27
  • 1970-01-01
  • 2020-04-23
  • 2019-04-27
  • 1970-01-01
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
  • 2011-05-04
相关资源
最近更新 更多