© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•7mo ago•
10 replies
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;
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"}
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Supabase signed URLs returning 404
SupabaseSSupabase / help-and-questions
14mo ago
Creating signed urls with download true missing file extension
SupabaseSSupabase / help-and-questions
13mo ago
Max expiration limit for Supabase signed URLs
SupabaseSSupabase / help-and-questions
2mo ago
new row violates row-level security policy while creating signed urls
SupabaseSSupabase / help-and-questions
2mo ago