Serving assets from Storage
Serving assets from Storage
Public buckets#
As mentioned in the Buckets Fundamentals all files uploaded in a public bucket are publicly accessible and benefit a high CDN cache HIT ratio.
You can access them by using this conventional URL:
https://[project_id].supabase.co/storage/v1/object/public/[bucket]/[asset-name]You can also use the Supabase SDK getPublicUrl to generate this URL for you
const { } = ..('bucket').('filePath.jpg').(.)Downloading#
If you want the browser to start an automatic download of the asset instead of trying serving it, you can add the ?download query string parameter.
By default it will use the asset name to save the file on disk. You can optionally pass a custom name to the download parameter as following: ?download=customname.jpg
Programmatic downloads with query parameters#
When using the SDK's download() method, you can pass additional query parameters to customize the download behavior:
import { createClient } from '@supabase/supabase-js'const supabase = createClient('your_project_url', 'your_supabase_api_key')// ---cut---// Download with custom filenameconst { data, error } = await supabase.storage.from('avatars').download('avatar1.png', { download: 'my-custom-name.png',})Private buckets#
Assets stored in a non-public bucket are considered private and are not accessible via a public URL like the public buckets.
You can access them only by:
- Signing a time limited URL on the Server, for example with Edge Functions.
- with a GET request the URL
https://[project_id].supabase.co/storage/v1/object/authenticated/[bucket]/[asset-name]and the user Authorization header
Signing URLs#
You can sign a time-limited URL that you can share with your users by invoking the createSignedUrl method on the SDK.
const { , } = await . .('bucket') .('private-document.pdf', 3600)if () { .(.)}Revoke signed URLs#
You can't revoke individual signed URLs. To invalidate a specific one, delete, move, or rename the underlying object.
Storage signs URLs with a dedicated internal key, separate from your project's Auth JWT signing key. Each project has its own key.
Because of this, signed URLs are not affected by:
- Rotating or revoking the Auth JWT legacy secret or signing key
- Disabling legacy keys in the Supabase Dashboard
- Switching from a shared secret (HS256) to an asymmetric (ES256) signing key
Signed URLs remain valid until their expiry time regardless of any Auth key changes.
To revoke all signed URLs, contact Supabase support to coordinate the internal key rotation.
Supabase then:
- Rotates the internal key, which invalidates all signed URLs (upload and download).
- Clears the CDN cache so the server validates every signed URL request directly before serving the object.
As a result, all existing signed URLs return a 404 error, and new signed URLs created after the rotation use the updated key.