Thomas Osayi

November 23, 2026 · 10 min read · Thomas Osayi

Supabase storage upload not working? Fix RLS, bucket, size and file type errors

Why Supabase storage uploads fail: storage.objects RLS policies, upsert, public vs private buckets, signed URLs, size limits, MIME types and CORS, with fixes.

File uploads are one of the first features that break when an AI-built app meets real users. The upload button works for the person who built it, then a customer tries to add a profile photo or a PDF and gets a red error, or nothing at all. In Supabase the cause is almost always one of a short list: policies, bucket settings, size, file type, or a request that fails for a different reason and looks like CORS.

This post goes through each one with the exact error text, the setting to check and the fix. It assumes the files live in Supabase Storage. If your problem is reading or writing normal database rows, "Is your Lovable or Bolt app leaking data? Check Supabase row level security" is the better starting point, and edge function failures are covered in "Supabase edge function errors: CORS, 401 Invalid JWT, missing secrets and timeouts".

Why does my Supabase storage upload fail?

Your upload fails because Supabase checked the request against your storage rules and something did not match: the policy, the bucket, the size, the type, or the user's session.

Every file in Supabase Storage is a row in a table called storage.objects, in the storage schema. When your app uploads a file, Supabase tries to insert a row there, and row level security on that table decides whether the signed-in user is allowed to. Bucket settings then add their own checks for size and file type.

So first read the actual error. Open the browser's developer tools, go to the Network tab, retry the upload and click the failed request to the storage endpoint. The status code tells you where to look:

  • 403 with "new row violates row-level security policy" or AccessDenied: a policy problem.
  • 400 "Asset Already Exists": the path is taken and upsert is off.
  • 400 InvalidMimeType: the bucket does not accept that file type.
  • 413 EntityTooLarge: the file is over a limit.
  • 404 NoSuchBucket: the bucket name in your code is wrong.
  • 401 InvalidJWT: the user's session is missing or expired.

What does "new row violates row-level security policy" mean for storage?

It means no policy on storage.objects allows this user to create, or read back, the row for the file they are uploading.

Supabase's documentation is direct about the default: Storage does not allow any uploads to buckets without RLS policies. A brand new bucket, public or private, accepts nothing from your app until you write an INSERT policy for it. AI tools often create the bucket and the upload code but skip the policy, or write a policy for a different bucket name.

There is a second, sneakier cause. Supabase's troubleshooting guide explains that when an upload uses upsert set to true, Storage runs an insert that also returns the row. If no SELECT policy covers that object, the database cannot return it, and the whole upload fails with the same 403, even though the INSERT policy would have allowed it.

So check two things:

  • Is there an INSERT policy on storage.objects for this bucket, for the role the user has (usually authenticated)?
  • Does the upload code set upsert to true? If so, is there a SELECT policy, and an UPDATE policy for overwriting?

If you do not need to overwrite files, the simplest fix is to drop upsert and upload each file to a new path.

Which storage policies do you actually need?

You need an INSERT policy to upload, SELECT to read or list in a private bucket, UPDATE to overwrite, and DELETE to remove files.

Policies are written in the SQL editor or the Storage policies screen in the dashboard. A common, safe pattern from Supabase's examples is a folder per user. The upload path starts with the user's ID, for example the user ID, then a slash, then the file name. The INSERT policy then checks two things: the bucket_id is the bucket you expect, and the first folder in the path, which you get with the helper storage.foldername(name), equals the signed-in user's ID from auth.jwt().

Described in words, a typical set for a user files bucket looks like this:

  • Insert, for authenticated users, only when the bucket matches and the first folder equals their user ID.
  • Select, for authenticated users, only for objects in their own folder (or where owner_id matches them).
  • Update, same rule as select, only if you overwrite files.
  • Delete, same rule, only if users can remove their own files.

Avoid policies that simply say true for every authenticated user. They let any user read or overwrite anyone's files.

Public or private bucket: which one is your app using?

A public bucket lets anyone read a file by its URL, while a private bucket checks policies on every operation, including reads.

This trips up a lot of generated code. The AI creates a private bucket, which is the default, then saves a public URL into the database and shows it in an image tag. The upload works, but every image is broken, because a private bucket does not serve files through public URLs. The reverse also happens: someone makes the bucket public to fix broken images and accidentally publishes every invoice or ID document in it.

Two facts from Supabase's bucket documentation settle most of these cases. Buckets are private by default. And making a bucket public only opens reading: uploading, deleting, moving and copying are still controlled by your policies, so a public bucket does not fix an upload 403.

Signed URLs for private files

For private files, create a signed URL with createSignedUrl when you need to show or download the file. The expiresIn value is in seconds, so 60 means the link stops working after one minute. Storing a signed URL in the database is a mistake, because it expires. Store the file path and create a fresh signed URL when the page loads.

There are also signed upload URLs, created with createSignedUploadUrl, which let a client upload to one specific path without further authentication. They are valid for two hours, and they are useful when your server decides where a file may go.

What are the file size limits?

On the Free plan, files cannot exceed 50 MB at the time of writing, and any bucket can set a lower limit of its own.

Supabase has a global file size limit, set in your project's Storage settings, which applies to all buckets. Free projects cannot raise it above 50 MB; paid plans can go much higher, up to 500 GB on Pro and Team according to the docs at the time of writing. Each bucket can then set a smaller maximum, for example 1 MB for avatars, but never more than the global limit. A file over either limit is rejected with a 413 EntityTooLarge error.

Size also affects how you should upload. Supabase describes standard uploads as ideal for files up to about 6 MB and recommends resumable uploads for anything larger, for reliability on slow or mobile connections. An app that sends a 40 MB video through a standard upload on phone data may fail intermittently even though it is under the limit.

Practical fixes:

  • Check the global limit and the bucket's limit before blaming the code.
  • Resize or compress images in the browser before upload. Phone photos are often several megabytes.
  • Show the limit in the interface, and check the size before sending, so users get a clear message instead of a failed request.

Why is my upload rejected for its file type?

Your bucket probably restricts allowed MIME types, and the file's type, as Supabase sees it, is not on the list.

When a bucket is created you can pass allowedMimeTypes, for example image wildcard to accept any image, plus a fileSizeLimit. A file that does not match is rejected with 400 InvalidMimeType. The detail that catches people is how the type is decided: if your code does not pass contentType, Supabase infers it from the file extension. A file with no extension, or a wrong one, can be stored as a generic type and fail the check, or succeed and then display as a download instead of an image.

Things to check:

  • The bucket's allowed types in the dashboard, under the bucket's settings.
  • That the upload passes contentType from the file object, for example image/jpeg.
  • Formats your users actually have. iPhone photos may be HEIC rather than JPEG, so either allow that type or convert before upload.
  • That the file input's accept attribute matches the bucket rules, so users cannot pick files that will be refused.

Is it really a CORS error?

Usually not. When an upload fails in the browser and the console says CORS, the request almost always failed for another reason first.

Browsers report CORS errors when a response is missing the headers they expect, and an error response from a misconfigured endpoint often lacks them. The Network tab tells you more than the console. If you see a real status code like 400, 403 or 413, fix that and the CORS message disappears.

The cases where CORS is the real problem tend to involve something between the browser and Supabase:

  • The app sends the file to your own API route or an edge function, which then forwards it, and that function does not answer the preflight OPTIONS request with the right headers.
  • The Supabase URL in your environment variables is wrong, for example a typo or a project you deleted, so the browser is talking to something that is not Supabase.
  • A custom header added to the upload triggers a preflight your proxy does not handle.

If your own function is in the path, "How to fix a CORS error on a Next.js API route" and the edge function post cover the headers it must return.

What mistakes does AI-generated upload code make?

The same handful of mistakes show up again and again in uploads written by AI tools.

  • The service role key in the frontend to make errors go away. It bypasses all policies, so anyone can read or delete every file. "API key exposed in your frontend? Which keys are safe and how to fix the rest" explains how to rotate it.
  • Upsert set to true on every upload, without SELECT and UPDATE policies.
  • File paths that do not start with the user's ID, so the folder based policy never matches.
  • A bucket name in code that differs from the real bucket in case or spelling, which returns 404 NoSuchBucket.
  • Public URLs saved for files in a private bucket, or signed URLs saved permanently.
  • Uploading before the session has loaded, so the request goes out as anonymous and fails with 401 or 403.

A worked example

Here is an illustration with a made-up app. A dog grooming booking tool, built in Lovable, lets customers upload a photo of their dog. In testing it works. After launch, customers report that the upload spins and then fails.

The Network tab shows a 403 with "new row violates row-level security policy". The bucket, pet-photos, is private and has an INSERT policy for authenticated users. The upload code, though, sets upsert to true, and there is no SELECT policy. The builder had been testing while signed in as the project owner through a different path, which hid the problem.

The fix takes three changes. Upload paths now start with the user's ID plus a random file name, so upsert is no longer needed and is removed. A SELECT policy lets users read files in their own folder. And the gallery, which was showing public URLs that never worked for a private bucket, now stores the path and creates a signed URL for 60 minutes when the page loads. The bucket also gets a 10 MB limit and an image only MIME rule, with a matching check in the form.

If you would rather hand this to someone, a single upload bug like this fits my Quick Fix, from $60 in about 2 days. If uploads are one of several broken features, Fix Plus Features starts at $200 for up to three fixes and one small feature.

The bottom line

When a Supabase storage upload is not working, read the failed request in the Network tab before changing anything. A 403 row-level security error means a missing INSERT policy, or upsert without SELECT and UPDATE policies. Broken images usually mean public URLs on a private bucket, and the fix is storing paths and creating signed URLs. 413 and InvalidMimeType point to size and type rules on the bucket or the project. CORS messages are usually a symptom. Write policies tied to the user's folder, keep the service role key on the server, and your uploads will behave the same for customers as they do for you.

Questions, answered in one line

Why does my Supabase upload say new row violates row-level security policy?

Because no policy on storage.objects allows this user to insert that file, or because the upload uses upsert and there is no SELECT policy letting the user read the row back.

Do public Supabase buckets need RLS policies?

Yes for writing. A public bucket lets anyone read files by URL, but uploading, deleting, moving and copying are still checked against your policies.

What is the maximum file size for Supabase storage?

On the Free plan the global limit cannot exceed 50 MB at the time of writing, while paid plans can raise it much higher, and each bucket can set its own lower limit.

How long do Supabase signed URLs last?

A signed download URL lasts for the number of seconds you pass in expiresIn, and a signed upload URL is valid for two hours.

Should I use the service role key to fix upload errors?

Not in the browser. The service role key bypasses all policies, so exposing it lets anyone read, overwrite or delete every file in your project.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service