Supabase Storage “Object not found” (404) – when the file is really there

By Abheesht Tripathi · Published

StorageApiError: Object not found   (HTTP 404, from createSignedUrl(), download() or a signed URL)

What it means

Supabase Storage keeps one row per file in storage.objects, protected by Row Level Security. When you ask for a signed URL or download a file, Storage looks up that row as the role your request runs as. If no row matches the bucket and path, or a row exists but no SELECT policy lets this role see it, the answer is the same: 404 with the message Object not found. Supabase's own error reference says the legacy not_found error means the resource “is not found or you don't have the correct permission to access it”. So a 404 here is often a permissions problem in disguise.

The usual causes, in the order to check them

  1. The path includes the bucket name. Paths are relative to the bucket. With .from('avatars') the path is user-id/photo.png, not avatars/user-id/photo.png. A leading slash, different letter case or a URL-encoded space (%20 vs a real space) also makes a different key.
  2. No SELECT policy on storage.objects for this role. You can upload with an INSERT policy and still be unable to read the file back. createSignedUrl() and download() need SELECT.
  3. The request runs as anon. In a route handler, server action or Edge Function, a Supabase client created without the user's session sends only the anon key, so a policy written to authenticated never matches.
  4. The upload never happened. upload() returns { error } instead of throwing. If nobody checks it, the file you think exists does not.
  5. Wrong project or bucket. Staging keys in production, or a file in avatars while the code reads avatar.

Step 1: confirm the exact key in SQL

In the SQL Editor (which runs as postgres and is not limited by RLS), look at what is really stored:

select bucket_id, name, owner_id, created_at
from storage.objects
where bucket_id = 'documents'
  and name ilike '%invoice%'
order by created_at desc
limit 20;

The name column is the exact path to pass to createSignedUrl(). If the row is missing, fix the upload. If the row is there, the problem is the path string or the policy.

Step 2: add a SELECT policy that matches your folder layout

The common layout is one folder per user, named after their id. Read access then looks like this:

create policy "read own files"
on storage.objects for select
to authenticated
using (
  bucket_id = 'documents'
  and (storage.foldername(name))[1] = (select auth.uid())::text
);

storage.foldername(name) splits the path into folders, so element 1 is the top-level folder. Upload with the same layout so the two always agree:

const { data: { user } } = await supabase.auth.getUser();
const path = `${user.id}/${file.name}`;            // no bucket name, no leading slash

const { error: upErr } = await supabase.storage.from('documents').upload(path, file);
if (upErr) throw upErr;

const { data, error } = await supabase.storage
  .from('documents')
  .createSignedUrl(path, 60 * 60);                 // valid for one hour
if (error) throw error;
console.log(data.signedUrl);

Step 3: make sure the server client carries the user

On the server, create the client from the request cookies (the @supabase/ssr server client) or pass the user's access token in the Authorization header. A quick test: call supabase.auth.getUser() on the same client right before createSignedUrl(). No user means the request is anon.

If a trusted backend job must sign URLs for any file, use a server-only client with the secret (service role) key, and check yourself that the caller may see that file. Never ship that key to the browser.

Two look-alikes

How to verify

Signed in as the owner, createSignedUrl() returns a URL that opens the file. Signed in as a second user, the same call returns Object not found. That second result is correct: it means other people cannot read the file.

FAQ

Why does Supabase Storage return 404 instead of 403 for a permissions problem?

Storage looks the object up through RLS. If no policy lets your role see the row, the lookup finds nothing, so you get 'Object not found'. Check the SELECT policy on storage.objects before assuming the file is missing.

Does createSignedUrl need an INSERT policy?

No. Creating a signed URL or downloading needs SELECT on the object. Uploading needs INSERT, and upload with upsert: true also needs SELECT and UPDATE.

Related guides

More in Supabase RLS and Storage · all guides