storage
storage copied to clipboard
file size
is there a way to get Storage file info before downloading (size, update date)?
Just saw this issue -- it's been a long time since you asked it so maybe you've found a way already, but I figured I'd share an idea.
Assuming you're using the normal supabase stack which includes postgrest, you could create a view in the public schema that exposes some of the data in the storage.objects table, for example:
create view public.objects as
select
name,
created_at,
updated_at,
last_accessed_at,
(metadata->'size')::int as size
from storage.objects;
then you could make requests to /rest/v1/objects to get that info:
$ curl -s -X GET 'https://your-app-id.supabase.co/rest/v1/objects' \
-H "apikey: <anon key>" \
-H "Authorization: Bearer <api key>" | jq
[
{
"name": "myfile",
"created_at": "2021-10-05T17:48:27.045129+00:00",
"updated_at": "2021-10-05T17:48:27.045129+00:00",
"last_accessed_at": "2021-10-05T17:48:27.045129+00:00",
"size": 6
}
]
I think this approach would apply RLS policies if you had them defined on your storage tables, but not 100% sure off the top of my head.
Yes the above solution will work nicely, just don't forget to add the the authenticated owner to the view for RLS to work
create view public.objects as
select
name,
created_at,
updated_at,
last_accessed_at,
(metadata->'size')::int as size
from storage.objects OWNER TO authenticated;