Today when I tried to update my firebase storage rules I got a message about upgrading them. How do I do that?
i deploying storage
i firebase.storage: checking storage.rules for compilation errors...
⚠ [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
✔ firebase.storage: rules file storage.rules compiled successfully
i storage: uploading rules storage.rules...
✔ storage: released rules storage.rules to firebase.storage
My rules looks like this:
service firebase.storage {
match /b/{bucket}/o {
match /user-files/{uid}/{allPaths=**} {
allow read: if resource.metadata[request.auth.uid] == "1"; // the uploading user can get a downloadURL
allow create, update: if request.auth.uid == uid // User can only upload to the users own folder
&& request.auth.token.storageLeft >= request.resource.size
&& request.auth.token.path == request.resource.name
allow delete: if false; // files are only deleted by cloud functions
}
}
}
Once you know who they are, you need a way to control their access to files in Cloud Storage. You can edit these rules by selecting a Firebase app in the Firebase console and viewing the Rules tab of the Storage section.
go to "Storage" Select "Rules" tab and edit rules as per below: service firebase. storage { match /b/{bucket}/o { match /{allPaths=**} { // Allow access by all users allow read, write: if request. auth !=
You can do this with the Cloud Storage SDK, which is bundled with the Firebase Admin SDK and accessible by calling admin. storage() . Now, calling the client-side method getDownloadUrl() on the file reference will give you a download URL that contains your newly created token.
To switch your rules to version 2, add this line at the top:
rules_version = "2";
To learn more about the new version of the rules language, see the documentation on getting started.
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