Flutter 无法将文件上传到 Firebase 存储
Flutter can not upload File to Firebase Storage
我只是想使用 Firebase CloudFirestore/Storage 上传图片。这是我的方法:
Future<void> uploadFile() async {
File file = File(croppedImagePath);
try {
int randomNumber = Random().nextInt(10000);
String imageLocation = 'images/image$randomNumber.jpg';
await FirebaseStorage.instance.ref(imageLocation).putFile(file); // <- crash
_addPathToDatabse(imageLocation);
} on FirebaseException catch (e) {
// e.g, e.code == 'canceled'
print(e.message);
}
}
但这会崩溃:
Exception has occurred.
MissingPluginException (MissingPluginException(No implementation found for method Task#startPutFile on channel plugins.flutter.io/firebase_storage))
这是我在pubspec.yaml
中添加的:
firebase_core: ^1.3.0
cloud_firestore: ^2.3.0
firebase_storage: ^9.0.0
我尝试了 运行 flutter clean
并且还多次重启了项目...我在这里缺少什么?为什么它不起作用?
我建议您检查文件是否正确,您也可以尝试将文件转换为字节。
在 运行 Flutter clean
之后,重新启动我的电脑并删除我的派生数据它再次工作...
我只是想使用 Firebase CloudFirestore/Storage 上传图片。这是我的方法:
Future<void> uploadFile() async {
File file = File(croppedImagePath);
try {
int randomNumber = Random().nextInt(10000);
String imageLocation = 'images/image$randomNumber.jpg';
await FirebaseStorage.instance.ref(imageLocation).putFile(file); // <- crash
_addPathToDatabse(imageLocation);
} on FirebaseException catch (e) {
// e.g, e.code == 'canceled'
print(e.message);
}
}
但这会崩溃:
Exception has occurred. MissingPluginException (MissingPluginException(No implementation found for method Task#startPutFile on channel plugins.flutter.io/firebase_storage))
这是我在pubspec.yaml
中添加的:
firebase_core: ^1.3.0
cloud_firestore: ^2.3.0
firebase_storage: ^9.0.0
我尝试了 运行 flutter clean
并且还多次重启了项目...我在这里缺少什么?为什么它不起作用?
我建议您检查文件是否正确,您也可以尝试将文件转换为字节。
在 运行 Flutter clean
之后,重新启动我的电脑并删除我的派生数据它再次工作...