编辑:清理项目并使缓存无效后,我刚刚重新启动了Android Studio。现在我收到此错误-
E/StorageException: { "error": { "code": 403, "message":
"Permission denied. Could not perform this operation" }}
我收到了无限打印的以下错误。
2020-09-27 17:00:32.931 11755-11863 / com.example.XXXXXX E / StorageUtil:获取令牌java.util.concurrent.ExecutionException时出错:com.google.firebase.internal.api.FirebaseNoSignedInUserException:请在尝试获取令牌之前先登录。
在我的应用中,我已经正确创建了用户,并且FirebaseAuth.getInstance().getCurrentUser();
不返回null。但是,如果可以,我可以通过成功登录他们或创建另一个用户来处理它。现在,我的应用在不到半天的时间内创建了160多个用户。我认为我甚至没有运行过该应用程序多次进行测试。验证设置中启用了“通过电子邮件登录”和“匿名登录”选项。
当我尝试访问存储时,问题开始了。我收到上述身份验证令牌错误。文件夹和文件存在,这就是我尝试下载文件的方式-
fstore.child("gs://XXXXXX-XXXX.appspot.com/Books/XXXX").listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for(StorageReference sref : listResult.getItems())
{
tempFilename = sref.getName();
File tmpFile = new File(tempSubDir, tempFilename);
try {
tmpFile.createNewFile();
sref.getFile(tmpFile).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(tabtwoactivity.this, "File download failed!", Toast.LENGTH_LONG).show();
System.out.println("ERROR: "+ e.toString());
}
});
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println("IIIIII: "+sref.getName());
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(tabtwoactivity.this, "Fetching Directory XXXXX Failed", Toast.LENGTH_LONG).show();
}
});
我尝试使用fstore.child("XXXX").listAll()
,但是这给了我很多错误的错误,主要集中在Folder not found
上。我的存储中包含文件夹和文件。我什至玩弄了存储规则-allow read, write;
,allow read, write: if request.auth!=null
,allow read, write: if request.auth==null
。但是什么都没有。
我在做什么错了?
答案 0 :(得分:1)
将其粘贴到您的google.json中:
service firebase.storage {
// The {bucket} wildcard indicates we match files in all storage buckets
match /b/{bucket}/o {
// Match filename
match /filename {
allow read: if true;
allow write: if true;
}
}
}