Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 403 Forbidden error when trying to load image from Firebase Storage

Tags:

I'm using firebase storage to store and load images for users on my android app. All users must be authenticated before using it. Occasionally, some user profile images are not showing and throwing "403 Forbidden" error. Those images were displaying before, I'm not sure why they stop working. i'm using the following rules on my firebase storage:

 service firebase.storage {    match /b/<storage_address>.appspot.com/o {     match /{allPaths=**} {      allow read: if request.auth != null;      allow write: if request.auth != null;     }   } } 

if i change the read rule to allow read; all the images are working properly. This is my display method:

Picasso.Builder builder = new Picasso.Builder(this);                 builder.listener(new Picasso.Listener()                 {                     @Override                     public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)                     {                         exception.printStackTrace();                     }                 });                 builder.build().load(URL).into(imgView); 

The image URL looks something like this:

https://firebasestorage.googleapis.com/v0/b/<storage_address>.appspot.com/o/images%2Fprofile%2Fphoto%2F36805?alt=media&token=e62ec151-3aaf-4e5c-aefb-1b3c93828684 

Could it be something to do with the token?

like image 773
bbenis Avatar asked Jan 30 '17 19:01

bbenis


People also ask

Why does it keep saying 403 Forbidden?

The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it. This status is similar to 401 , but for the 403 Forbidden status code re-authenticating makes no difference.

How do I fix REST API 403 Forbidden?

Check the Requested URL The most common cause of a 403 Forbidden Error is simply inputting an incorrect URL. As discussed before, many tightly secured web servers disallow access to improper URLs. This could be anything from accessing a file directory to accessing a private page meant for other users.


1 Answers

Probably comes too late, but maybe helpful for someone else. I had the same issue, my problem is that filenames in firebase storage are unique. If you upload a new file with the same filename it will override the old one and generate a new token for it, making the old url obsolete. You should generate a unique filename for your uploaded file and then it should be fixed.

like image 195
user2555964 Avatar answered Sep 22 '22 07:09

user2555964