Upload file to bucket with metadata from client side
Hey everyone!
I'm using the JavaScript library with Supabase client to upload/list/download files from client side. I would like to store custom metadata like the real filename.
Currently I upload like:
But when I list files, the metadata only shows system fields (eTag, size, mimetype), not my custom filename:
How do I retrieve the custom metadata I uploaded? Is there a getMetadata() method or different approach needed?
15 Replies
Update: found something related
The .info() method works for retrieving custom metadata:
But you need N queries for N files (vs 1 query with .list()), so there's a performance trade-off. Using filename patterns for now but .info() definitely works if needed.
I had just found that as I could not find it in docs.
That is the only way I know currently.
But it makes sense for list to do it.
I would file an issue in supabase/storage asking for that to be in the list.
Hmm I'll create new issue about it. looks like the server should return it
@graboosky 🥷 I'm thinking about a workaround to make a server-side endpoint that receives list of IDs and returns the user metadata
If you check in the body of the response is it there?
since the paths are UUIDs it should be relatively safe. what do you think?
It's not there sadly with
list()
Only with info()
for individual fileSo you looked in the network data coming back and not there. So not a storage-js issue, but a storage server issue.
You can have an rpc access storage.objects and return what ever you like.
Sounds good. like RPC that will return the metadata list for list of object IDs?
You can use whatever filter you want on storage.objects and return what you feel is safe. You can use auth.uid() to limit to that user.
Yea it doesn't return the metadata. it's null. but it's there in the table in the storage schema!
Yes info works so it is stored correctly.
Just list does not seem to have it based on what you are saying. I've not test list. I'll do that. I tested info and it is working.
btw I don't want to invent new
list
function and stick to supabase because of the pagination and security they put into it
yea info works for me tooList does not return it.
Just verified.
Hmm
sounds like the only option is to create custom list RPC function that returns metadata+user metadata
I see owner_id in the objects schema, will try to verify if it's equal to the sub (user id)
For the moment.
I would ask them to add it. Seems like an oversite.
the owner id equals to the sub!!
cool
will try now to use something like this
Created new issue in supabase storage https://github.com/supabase/storage/issues/759