Ali*_*der 5 flutter firebase-storage
我将在 firebase 存储中存储图像。当我通过图像选择器发送文件时,它工作正常。但是当我手动传递图像链接时,它显示一个错误:
'package:firebase_storage/src/storage_reference.dart':
Failed assertion: line 62 pos 12: 'file.existsSync()': is not true.
Run Code Online (Sandbox Code Playgroud)
我正在编写以下代码:
File image = File("assets/img/pic.jpg");
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child('image');
InkWell(
child: Text("Tap to Upload"),
onTap: () {
firebaseStorageRef.putFile(image);
},
),
Run Code Online (Sandbox Code Playgroud)
错误表明,该文件不存在,在执行此操作之前,您应该检查该文件是否存在,如果不存在则创建它
InkWell(
child: Text("Tap to Upload"),
onTap: () async {
File image = await File("assets/img/pic.jpg").create();
// it creates the file,
// if it already existed then just return it
// or run this if the file is created before the onTap
// if(image.existsSync()) image = await image.create();
firebaseStorageRef.putFile(image);
},
),
Run Code Online (Sandbox Code Playgroud)
另外,我不确定您是否可以在资产文件夹中更改/创建文件,如果这不起作用,可以尝试将文件放入应用程序的临时目录中
| 归档时间: |
|
| 查看次数: |
7607 次 |
| 最近记录: |