提问人:085Pushpraj Singh Pawar 提问时间:4/6/2023 最后编辑:Frank van Puffelen085Pushpraj Singh Pawar 更新时间:4/6/2023 访问量:53
如何在 flutter 的 firebase 存储中上传时正确处理任何异常
How to properly handle any exceptions while uploading in firebase storage in flutter
问:
这是我将 2 个文件上传到 firebase 存储的功能,我不确定我是否使用了正确的异常处理,其次是将 await 语句放在哪里以留出时间上传自己。
void _uploadtocloud() async {
//File? filesong,fileimage; initialized outside the function
String songname = songName.text.toString();
String thumbnail = '${songName.text}thumbnail';
final Reference storageRef =
FirebaseStorage.instance.ref().child('music/$songname');
final UploadTask uploadTaskSong = storageRef.putFile(filesong!);
final Reference storageRefimage =
FirebaseStorage.instance.ref().child('image/$thumbnail');
final UploadTask uploadTaskimage = storageRefimage.putFile(fileimage!);
final TaskSnapshot snapshot1 = await uploadTaskSong;
final TaskSnapshot snapshot2 = await uploadTaskimage;
if (snapshot1.state == TaskState.success &&
snapshot2.state == TaskState.success) {
await Future.delayed(const Duration(seconds: 10));
//is this the right place to put await statement.
setState(() {
uploaded = true;
songName.clear();
});
} else {
setState(() {
uploadfaliure = true;
});
}
}
答: 暂无答案
评论