← All posts
·7 min read·GuardLayer·how we write

Supabase Storage "Bucket not found": causes and the fix

#supabase#storage#signed-urls#rls#security

{"statusCode":"404","error":"Bucket not found","message":"Bucket not found"} from Supabase Storage usually means you opened a public URL for a private bucket: the /object/public/ route only looks for buckets marked public, so a private one reads as missing. Serve the file with createSignedUrl() instead. The other causes are a misspelled bucket or the wrong project, and getBucket() called from the browser. Don't make the bucket public to silence the error, because that hands every file in it to anyone with the link.

The confusing part is that the bucket exists. You can see it in the dashboard, uploads to it work, and the URL has the right name in it. The error is still accurate, because of how that URL is looked up.

Why does Supabase say "Bucket not found" when the bucket exists?

Because the public URL route searches only public buckets. In the Storage server, the handler for GET /storage/v1/object/public/:bucketName/* (src/http/routes/object/getPublicObject.ts) looks the bucket up as the superuser with a filter:

request.storage.asSuperUser().findBucket(bucketName, 'id,public', {
  isPublic: true,
})

That adds public = true to the query. A private bucket doesn't match, the lookup comes back empty, and findBucketById throws NoSuchBucket. Its definition in src/internal/errors/codes.ts sets error: 'Bucket not found', message: 'Bucket not found' and httpStatusCode: 404. The error handler sends most storage errors with HTTP status 400 and puts the 404 in the body as a string. That's why you see a 400 in the network tab with "statusCode": "404" inside it.

Nothing on your side warns you first. In storage-js, getPublicUrl() is synchronous and only builds a string:

const { data } = supabase.storage.from("invoices").getPublicUrl(`${userId}/inv-1042.pdf`);
// data.publicUrl === "https://<ref>.supabase.co/storage/v1/object/public/invoices/<userId>/inv-1042.pdf"
// no request was made, and there is no error field

It returns { data: { publicUrl } } for any bucket and any path, whether or not either exists. The error only appears when a browser, <img> tag or fetch actually requests that URL.

The three causes, in order of likelihood

SymptomCauseFix
Public URL fails, uploads and dashboard workPrivate bucket opened through getPublicUrl()createSignedUrl(), or download() with the user's session
Every request fails, in one environment onlyBucket name typo, or the client points at another projectCheck the exact id and NEXT_PUBLIC_SUPABASE_URL
getBucket() fails in the browser, listBuckets() returns []No select policy on storage.buckets for that roleSkip the bucket call; use from(bucket) directly

1. A public URL for a private bucket

This is the common one: a bucket created private (the default) and code that displays files with getPublicUrl(). Uploads work because they go through the authenticated route and your storage.objects policies. Reads through /object/public/ never get that far.

The fix is a signed URL, created where you can check who's asking:

// app/invoices/[id]/page.tsx (server component)
const supabase = await createClient(); // @supabase/ssr server client, user's session

const { data, error } = await supabase.storage
  .from("invoices")
  .createSignedUrl(`${user.id}/inv-1042.pdf`, 60); // valid for 60 seconds

if (error) throw error;
return <a href={data.signedUrl}>Download invoice</a>;

createSignedUrl() runs as the signed-in user, so it needs a select policy on storage.objects for that path. The usual per-user folder policy is enough:

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

For a list of files, createSignedUrls(paths, 60) signs them in one request. Keep the expiry short: a signed URL is a bearer link, and you can't revoke a single one, only every signed URL in the project at once.

2. The bucket really isn't in this project

Bucket ids are compared as plain strings, so Invoices and invoices are different buckets. Copy the id from the dashboard instead of typing it.

The other version is a bucket that exists in one project but not the one the client talks to. A bucket created by clicking in the dashboard of your dev project doesn't exist in production. Neither does one that only exists in your local Supabase. Preview deployments that inherit production env vars, or the other way round, cause the same thing. Create buckets in a migration so every environment gets them:

insert into storage.buckets (id, name, public)
values ('invoices', 'invoices', false)
on conflict (id) do nothing;

3. Bucket calls from the browser

Unlike the public route, the Storage server's getBucket and listBuckets handlers query as the current user, so RLS on storage.buckets applies, and most projects have no select policy there. So getBucket('invoices') answers "Bucket not found" and listBuckets() returns an empty array. It's the same silent-filter behaviour as a select that returns an empty array on any other table.

You rarely need either call on the client. supabase.storage.from('invoices') doesn't look the bucket up at all. If you do need bucket metadata, read it on the server.

The fix that makes it worse

A common answer to this error is to make the bucket public. It works instantly, which is the problem.

guardlayer scan · supabase/migrations/20261125090000_fix_invoice_urls.sqlLive engine output
Check failed
75/100 · B
  • Criticalsupabase/migrations/20261125090000_fix_invoice_urls.sql:3

    Public storage bucket

    Set public: false and serve files through signed URLs (createSignedUrl) or RLS-protected access. Only keep a bucket public for genuinely public assets.

After that migration, every object in invoices is served to anyone who has its URL, with no login and no RLS check. That includes other users' invoices, files uploaded before the change, and anything uploaded later. Paths like <user-id>/inv-1042.pdf leak through referrer headers, logs and shared links, and they're often guessable. The full breakdown of what a public bucket exposes is in public vs private buckets.

GuardLayer flags this as supabase/public-storage-bucket in three forms: an update storage.buckets set public = true like the one above, an insert into storage.buckets with public set to true, and a client call such as storage.updateBucket(name, { public: true }) or createBucket(name, { public: true }). Each finding comes with the file and line.

A public bucket is right for files you'd be happy to post anywhere: logos, marketing images, public downloads. For anything a user uploaded, keep the bucket private and fix the URL instead.

How do I check my own project?

In the SQL Editor, list your buckets and their flag:

select id, public, created_at
from storage.buckets
order by created_at;

Then find every place the code builds a public URL, and check each against that list:

grep -rn "getPublicUrl\|/object/public/" app lib components

A getPublicUrl() call on a private bucket is a broken link today. A bucket that turns out to be public while it holds user files is the bigger problem: switch it to private, move its reads to signed URLs, and treat what was in it as already exposed.

FAQ

Why does my upload work but the public URL says "Bucket not found"? They take different routes. Uploads go through the authenticated object route and your storage.objects insert policy. The public URL goes to /object/public/, which only finds buckets with public = true. A private bucket passes the first and fails the second.

Does getPublicUrl() check that the file or bucket exists? No. It builds the URL string locally and never makes a request, so it can't return an error. Only fetching the URL tells you whether it works.

Why does the network tab show 400 when the body says 404? Supabase Storage sends most errors with HTTP status 400 and puts the original status in the body's statusCode field as a string. Check the body, not the status line, to tell "Bucket not found" from "Object not found" or an RLS error.

Is it safe to add a select policy on storage.buckets so getBucket() works? It exposes bucket metadata, such as names, the public flag and size limits, not files. That's low risk, but you rarely need it. from(bucket) works without it, and an upload blocked by RLS is governed by storage.objects, not storage.buckets.

How long should a signed URL for a private file last? As short as the page needs: 60 seconds is plenty for a download link or an image you render right away. Create a fresh one on each request instead of caching it.

live check · read-only

See which of your Supabase tables anyone can read, free

Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading