我尝试上传到存储的图像成功,但是当我想使用上传的图像将URL存储到数据库中时,由于某种原因,它返回空值。
Future<String> _uploadPic(String docRef, File file) {
FirebaseStorage _storage = FirebaseStorage.instance;
auth.currentUser().then((userID) async{
StorageReference reference = _storage.ref().child(userID).child(docRef);
StorageUploadTask uploadTask = reference.putFile(file);
String downloadURL = (await uploadTask.onComplete).ref.getDownloadURL().toString();
return downloadURL;
});
}
原木:
I/flutter (17507): debug: the uri is: null
最佳答案
Future<dynamic> _uploadPic(String docRef, File file) {
FirebaseStorage _storage = FirebaseStorage.instance;
// you need to return the result...
return auth.currentUser().then((userID) async {
StorageReference reference = _storage.ref().child(userID).child(docRef);
StorageUploadTask uploadTask = reference.putFile(file);
return (await uploadTask.onComplete).ref.getDownloadURL();
});
}
关于flutter - uploadTask完成后,getDownloadURL返回null,但将图像上传到存储,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57546623/