Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using google firebase storage without authentication

I want to share some json file to all user without server and I use google firebase storage service (without user authentication). Code:

FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://xxxxxx.appspot.com/xxx-main.json");
Task<byte[]> task = storageRef.getBytes(1000000);
while (!task.isComplete())
    StaticTools.sleep(100);

byte[] b=task.getResult();

but it raise an exception:

com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.storage.StorageException: User does not have permission to access this object.

Storage Rule:

service firebase.storage {
  match /b/XXXXXX.appspot.com/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
like image 604
shafaghi Avatar asked May 25 '16 07:05

shafaghi


People also ask

Can I use Firebase without authentication?

This Firebase Realtime Database URL is accessible without authentication. If the database contains sensitive information it's recommended to restrict access to this database.

How do I access Firebase Storage without token?

To do that, one of the easiest way is using the Google Cloud Console Storage. Select the bucket, click the bucket to configure and open the permissions tab. Since this is Firebase managed bucket, it would have what Google called fine-grained access control. Don't worry, adding public access is quite simple.

Can I use Firebase without Google account?

Using Firebase requires that you as the developer have a Google account. But your app's users don't need to have a Google account, unless you want them to. In fact, if you don't use Firebase Authentication, you can work with completely unidentified users for most services.

Can I use Firebase Storage for free?

Firebase offers a no-cost tier pricing plan for all its products. For some products, usage continues at no cost no matter your level of use. For other products, if you need high levels of use, you'll need to switch your project to a paid-tier pricing plan.


3 Answers

Use the new Firebase Storage Console at https://console.firebase.google.com. Navigate through your folders and select your uploaded file. Under the File location tab, there is this field called Download URL. Click on it to copy and you will be able to hotlink to this file in your website.

As long as there is no permission settings written in the rules tab, you should be able to use these files publicly.

like image 109
Xavier J. Wong Avatar answered Sep 24 '22 14:09

Xavier J. Wong


Xavier's answer with Download URLs will work.

Your rules should allow public read, but it can take up to 5 minutes for your rules to update across the system.

like image 23
katfang Avatar answered Sep 22 '22 14:09

katfang


I Use this for the latest firebase it worked

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

I just delete in if condition.

like image 29
Hario Budiharjo Avatar answered Sep 22 '22 14:09

Hario Budiharjo