Android 如何获得我上传到firebase的照片的精确参考
这是我上传图片的代码Android 如何获得我上传到firebase的照片的精确参考,android,firebase,flutter,firebase-storage,Android,Firebase,Flutter,Firebase Storage,这是我上传图片的代码 Future uploadProfileImage() async { final StorageReference profileImageStorageRef = FirebaseStorage.instance.ref().child("Profile Images"); var currentUserPicture = user.uid.toString(); final StorageUploadTas
Future uploadProfileImage() async {
final StorageReference profileImageStorageRef =
FirebaseStorage.instance.ref().child("Profile Images");
var currentUserPicture = user.uid.toString();
final StorageUploadTask profileUploadTask = profileImageStorageRef
.child(currentUserPicture.toString() + ".jpg")
.putFile(myImage);
var imageUrl =
await (await profileUploadTask.onComplete).ref.getDownloadURL();
setState(() {
profilePicUrl = imageUrl.toString();
print("Image name = " + profilePicUrl);
});
}
我的firebase数据存储中显示的只是“Future”的实例我没有立即看到代码中有什么错误,但是在一行中有两个wait语句使得快速扫描正在发生的事情变得很困难 我建议重写如下:
Future uploadProfileImage() async {
var profileImageStorageRef = FirebaseStorage.instance.ref().child("Profile Images");
var currentUserPicture = user.uid;
var useImageStorageRef = profileImageStorageRef.child(currentUserPicture + ".jpg")
var profileUploadTask = useImageStorageRef.putFile(myImage); // start upload in background
await profileUploadTask.onComplete; // wait for upload to complete
var imageUrl = await useImageStorageRef.getDownloadURL(); // wait for the download url
print("Image name = " + profilePicUrl);
setState(() {
profilePicUrl = imageUrl.toString();
});
}
嘿,布莱恩。你有机会测试一下我答案的变化吗?有什么不同吗?