Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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-与Firebase_auth一起使用Firebase_存储_Firebase_Flutter_Firebase Storage - Fatal编程技术网

颤振与振动;Firebase-与Firebase_auth一起使用Firebase_存储

颤振与振动;Firebase-与Firebase_auth一起使用Firebase_存储,firebase,flutter,firebase-storage,Firebase,Flutter,Firebase Storage,使用firebase软件包: 我可以使用firebase_auth登录到firebase,那里的一切都很好,但是当我使用firebase_存储包上载文件时,访问被拒绝,我必须进入firebase并将权限设置为: service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write;//: if request.auth != null; } } } 这对于使用身份验证的应

使用firebase软件包:

我可以使用firebase_auth登录到firebase,那里的一切都很好,但是当我使用firebase_存储包上载文件时,访问被拒绝,我必须进入firebase并将权限设置为:

service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
  allow read, write;//: if request.auth != null;
   }
 }
}

这对于使用身份验证的应用程序并不理想,我如何告诉firebase_存储包我通过firebase_身份验证包进行了身份验证?

您不应该有这个问题,我共享一个适用于我的代码

Future<Null> ensureLoggedIn() async {
  FirebaseUser firebaseUser = await auth.currentUser();
  assert(firebaseUser != null);
  assert(!firebaseUser.isAnonymous);
}

Future<String> uploadFile(File file) async {
    assert(file != null);
    await ensureLoggedIn();
    int random = new Random().nextInt(100000);
    String _instance = '/files/image_$random.jpg';

    StorageReference ref = FirebaseStorage.instance.ref().child(_instance);
    StorageUploadTask uploadTask = ref.putFile(file);

    final Uri downloadUrl = (await uploadTask.future).downloadUrl;

    return downloadUrl.toString();
  }
Future ensureLoggedIn()异步{
FirebaseUser FirebaseUser=wait auth.currentUser();
断言(firebaseUser!=null);
断言(!firebaseUser.isAnonymous);
}
未来上传文件(文件)异步{
断言(文件!=null);
等待确认登录();
int random=new random().nextInt(100000);
字符串_instance='/files/image_$random.jpg';
StorageReference ref=FirebaseStorage.instance.ref().child(\u instance);
StorageUploadTask uploadTask=ref.putFile(文件);
最终Uri downloadUrl=(等待uploadTask.future);
返回downloadUrl.toString();
}

请编辑您的问题,以包含无法按预期方式工作的相关代码。请确保检查日志并包含任何相关的错误消息。就你现在的问题而言,我们无能为力。Firebase存储SDK不需要被告知Firebase身份验证-它们自动协同工作。感谢您修复了它。。。。“StorageReference ref=FirebaseStorage.instance.ref().child(_instance);“我有”最终StorageReference ref=widget.storage.ref().child('text')。child('foo.txt');”