Supabase Storage best practice

I'm looking to use supabase storage to save user uploaded images with the following requirements: 1. The user will be able to upload multiple images. 2. The images will be read in one of two ways: a) The user visits their profile and sees all of their own images (or that of another user if they visit their profile). b) The user browses their "feed" and sees images from a variety of other users. What would be the best way to go about structuring this? I'm thinking currently I'd just make a bucket for each user, but I'd hate to get to far along in implementing it and it turn out there was a much better approach or find out that it doesn't scale at all.
6 Replies
garyaustin
garyaustin2y ago
Don't have a bucket per per user. Make a "folder" using the path have the user's UUID in it. Then protect with RLS policies as needed.
fuzzy_discussion911
Thank you! Just to clarify, basically you're saying to upload all user uploaded images to one bucket, and then set the filename to something like
const fileName = `${User_UUID}/<xyz>.${fileExt}`
const fileName = `${User_UUID}/<xyz>.${fileExt}`
and then query based on the filename when needed?
garyaustin
garyaustin2y ago
Yes.
fuzzy_discussion911
Would you recommend following this approach for all media? For example, say user avatars. Would it be better to do something like that and adding in /avatar/ to the filename than making a seperate avatar bucket? When would another bucket be advantageous?
garyaustin
garyaustin2y ago
You normally want separate buckets if you will have different policies for RLS on them, or for totally different things. So avatar bucket and a product images bucket.
fuzzy_discussion911
Awesome, thank you very much for your help.

Did you find this page helpful?