Published on

How to get Signed file URL for Supabase Storage in Node

Authors

You can use Supabase Storage to store your files as well and they have a flexible API/SDK as well which makes it easier to interact with it.

Your files can be stored public or privately depending on your use case. And if you want to make a file public for a limited period then you can get a signed URL for that file and configure the time until when the URL will be valid.

Here's how to get the signed URL

npm install @supabase/supabase-js ms

And get the values for SUPABASE_URL and SUPABASE_PRIVATE_KEY from the Supabase dashboard as well.

// supabaseAdminClient.js
import { createClient } from '@supabase/supabase-js';

const SUPABASE_URL = process.env.SUPABASE_URL;
const SUPABASE_PRIVATE_KEY = process.env.SUPABASE_PRIVATE_KEY;

const supabaseAdmin = createClient(SUPABASE_URL, SUPABASE_PRIVATE_KEY);

export default supabaseAdmin;
// ms package is used to convert various time formats to milliseconds
import ms from 'ms';

const bucketName = 'example';
const path = '/example/hello.jpg'
const { data: { signedUrl } } = await supabaseAdmin
.storage
.from(bucketName)
.createSignedUrl(path, ms('5m'))

Happy sharing files!