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;
}
}
}
This Firebase Realtime Database URL is accessible without authentication. If the database contains sensitive information it's recommended to restrict access to this database.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With