'I want to create an app in which user can access the only files uploaded by him [closed]
We have created a Android app in which we have added the features so that multiple users can create an account and login to upload or download there personal files. But it has become quite different all the files that are store to real time database of firebase through different user everyone who login get access of it to download it or read it etc. I want to creat an app so that the file upload by user will be accessed only by that same user who uploaded it. What should I do? Is there any sort of rule for it?
Solution 1:[1]
The easiest way to do this is by storing all images for a specific user under a path/directory with their UID in it, and then use security rules to protect access based on that path.
This is actually an example in the Firebase documentation on securing content-owner only access with these rules:
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/{bucket}/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |
