1
我正在尝试使用Firebase下载PDF文件。每当我点击应该启动下载的项目,下载失败。 我在日志监视器中看到此消息: -无法从FireBase下载文件
StorageException发生。用户没有权限访问此对象。代码:-13021 HttpResult:403
我在火力地堡控制台读/写权限如下: -
service firebase.storage {
match /b/savephoto-a1cc3.appspot.com/o {
match /{allPaths=**} {
// Allow access by all users
allow read, write;
}
}
}
而且我对下载文件的Java代码看起来像这样
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReference();
StorageReference islandRef = storageRef.child("CSD-101").child("Midsems").child("2016").child("CSD101_MidSem.pdf");
File rootPath = new File(Environment.getExternalStorageDirectory(), "Question Papers");
if(!rootPath.exists()) {
rootPath.mkdirs();
}
final File localFile = new File(rootPath,"CSD-101 Midsems.pdf");
islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(Year2.this, "File Downloaded", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Year2.this, "Download Failed", Toast.LENGTH_SHORT).show();
}
});
我能做什么?
它需要大约5分钟[修改安全规则(https://firebase.google.com/docs/storage/security/开始#edit_rules)成为现场。如果在更改规则以允许公开访问后立即发生故障,请重试。 –
我甚至在一个小时后试过,但它没有工作:( –