Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 图像Url为空_Firebase_Flutter_Google Cloud Firestore_Firebase Authentication - Fatal编程技术网

Firebase 图像Url为空

Firebase 图像Url为空,firebase,flutter,google-cloud-firestore,firebase-authentication,Firebase,Flutter,Google Cloud Firestore,Firebase Authentication,如果第一次调用该函数,URL将返回null,但如果我再次调用它,它将返回正确的URL。请帮我找出代码的错误。 如果我单击RaiseButton一次,它返回null,但是如果我单击第二次,它返回正确的URL Future uploadImageToFirebase() async{ FirebaseStorage _storage = FirebaseStorage.instance; StorageReference reference = _storage.ref().chi

如果第一次调用该函数,URL将返回null,但如果我再次调用它,它将返回正确的URL。请帮我找出代码的错误。 如果我单击RaiseButton一次,它返回null,但是如果我单击第二次,它返回正确的URL

 Future uploadImageToFirebase() async{
    FirebaseStorage _storage = FirebaseStorage.instance;
    StorageReference reference = _storage.ref().child("Products/${Path.basename(_image.path)}");
    StorageUploadTask uploadTask = reference.putFile(_image);
    await uploadTask.onComplete;
    reference.getDownloadURL().then((fileURL) {
      setState(() {
        url = fileURL.toString();
      });
    });
    print(url);
  }
这是我的firebase存储安全规则

W/StorageUtil( 9524): no auth token for request
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
W/StorageUtil( 9524): no auth token for request
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
W/StorageUtil( 9524): no auth token for request
I/flutter ( 9524): null
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
D/ViewRootImpl@8f09ed9[MainActivity]( 9524): ViewPostIme pointer 0
D/ViewRootImpl@8f09ed9[MainActivity]( 9524): ViewPostIme pointer 1
W/StorageUtil( 9524): no auth token for request
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
W/StorageUtil( 9524): no auth token for request
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/flutter ( 9524): https://firebasestorage.googleapis.com/v0/b/bridcodes-seller.appspot.com/o/Products%2Fimage_cropper_1598948384298.jpg?alt=media&token=cc418efc-8402-4a96-a0f0-939a3a171373
W/StorageUtil( 9524): no auth token for request
W/NetworkRequest( 9524): no auth token for request
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out( 9524): (HTTPLog)-Static: isSBSettingEnabled false

更新firebase Storages中的安全规则查看一下-这将有助于您了解
然后
的工作原理。我查看了此解决方案,但它仍然不适用于我。此代码是否存在问题?我看到您正在从onComplete方法分配等待的值,这看起来是捕获相关结果对象的更好方法。
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /Products/{allPaths=**} {
      allow read, write;
    }
  }
}
    Future<String> uploadImageToFirebase() async {
    FirebaseStorage _storage = FirebaseStorage.instance;
    StorageReference reference = _storage.ref().child("Products/${Path.basename(_image.path)}");
    StorageUploadTask uploadTask = reference.putFile(_image);
    StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
    final String url = await taskSnapshot.ref.getDownloadURL();
    return url;
  }
    uploadDetails(context) async {
    if(_formKey.currentState.validate()) {
      _formKey.currentState.save();
      if(_image != null) {
        imgUrl = await uploadImageToFirebase();
        Firestore.instance.collection("Products").add({
          'ImgUrl': imgUrl,
        });
      }
    }
  }