简体   繁体   中英

Unable to download files from FireBase

I am trying to download a pdf file using Firebase. Whenever I click the item which should initiate the download, the download fails. And I get this message in the log monitor:-

StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403

My read/write permission in the Firebase console looks like this:-

service firebase.storage {
  match /b/savephoto-a1cc3.appspot.com/o {
    match /{allPaths=**} {
      // Allow access by all users
      allow read, write;
    }
  }
}

Also my java code for downloading the file looks like this

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();
    }
});

What can I do?

you should update your firebase console rules with this code

{  "rules": {
".read": true,
".write": true}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM