S
Supabase2mo ago
seno

Signed urls with api call

I am making an api call for a table called "post". the post table has a column called "media" which is list of file urls. however, the file url bucket is private. so I would need to sign the urls first and then get them. i have this function but it is not working. what should i do? thanks DECLARE v_processed_urls TEXT[] := ARRAY[]::TEXT[]; v_path TEXT; v_full_url TEXT; v_base_url TEXT; BEGIN -- If the input array is NULL or empty, return an empty JSON array IF p_media_paths IS NULL OR array_length(p_media_paths, 1) IS NULL THEN RETURN '[]'::jsonb; END IF; -- Get the base URL for your Supabase project storage -- Replace 'your-project-id' with your actual project ID -- You can also store this in a settings table or environment variable v_base_url := 'https://your-project-id.supabase.co/storage/v1/object/posts/'; -- Loop through each path in the input array FOREACH v_path IN ARRAY p_media_paths LOOP -- For now, we'll construct public URLs -- Note: These will be public URLs, not signed URLs IF v_path IS NOT NULL AND v_path != '' THEN v_full_url := v_base_url || v_path; v_processed_urls := array_append(v_processed_urls, v_full_url); END IF; END LOOP; -- Return the array of URLs as JSONB RETURN to_jsonb(v_processed_urls); END; {"code":"42883","details":null,"hint":"No function matches the given name and argument types. You might need to add explicit type casts.","message":"function storage.sign_url(text, text, integer, jsonb) does not exist"}
7 Replies
garyaustin
garyaustin2mo ago
What is storage.sign_url? You should not put functions in storage if that is what you are doing. Also why not just return paths and then get URLs with API
seno
senoOP2mo ago
@garyaustin thanks I think it is the function AI tried to assume exists... I think it tried to derive it from this (see image) not sure what you mean with "Also why not just return paths and then get URLs with API"? I was thinking of signing them in the backend as it is easier
No description
garyaustin
garyaustin2mo ago
But there is nothing built in the backend to sign them. You have to call the storage REST API to get them signed. Maybe use an edge function to get the table data and then get the paths to signed URLs with REST API calls and then return all of that. Actually there is a REST API call to pass an array of paths so only one REST call.
seno
senoOP2mo ago
can you address me to that REST API call? I cant seem to find it thanks
garyaustin
garyaustin2mo ago
You actually just linked it. Or the JS version.
seno
senoOP2mo ago
hmm I am using nocode tools and am not finding the Rest api version

Did you find this page helpful?