Supabase Storage upload: “new row violates row-level security policy”
Last verified: October 18, 2026
StorageApiError: new row violates row-level security policy
What it means
Supabase Storage doesn't allow uploads to a bucket until you add RLS policies on the storage.objects table. Making a bucket “public” only makes files readable. Uploads still need an INSERT policy, and overwriting with upsert also needs SELECT and UPDATE.
How to fix it
- Note the bucket name the upload uses and whether the user is logged in when uploading.
- In Supabase → Storage → Policies, add an INSERT policy on
storage.objectsforauthenticatedwithbucket_id = 'your-bucket', ideally limited to a folder named after the user id. - If the code uses
upsert: trueto replace files, add matching SELECT and UPDATE policies too. - Upload again as a logged-in user and confirm the file appears in the bucket.
If your Lovable project uses Lovable Cloud instead of your own Supabase project, the same database lives under More → Cloud → Database. Its RLS view is read-only, so ask Lovable in chat (Plan mode) to make the policy change.
Stop the loop: paste these into Lovable
1. Diagnose first
Stop editing and don't retry earlier fixes. Uploading to Supabase Storage fails with: new row violates row-level security policy. Without changing anything, show me the upload code (bucket name, file path, whether upsert is used), confirm whether the user is authenticated at upload time, and list the existing policies on storage.objects for that bucket. State the cause in one sentence and propose ONE minimal change.
2. Then the one fix
Add only the missing Storage policy: an INSERT policy on storage.objects to authenticated with check (bucket_id = 'BUCKET' and (storage.foldername(name))[1] = (select auth.jwt()->>'sub')), and make the upload path start with the user's id. If upsert is used, also add SELECT and UPDATE policies with the same conditions. Don't make the bucket writable by anonymous users and don't use the service role key in the browser. Test an upload while logged in and tell me exactly what SQL you ran.
3. Save this rule so it stays fixed
Lovable: Project settings → Knowledge. Cursor: .cursor/rules or .cursorrules. Bolt: Project settings → Knowledge. Replit: replit.md.
Rule: Every Storage bucket the app writes to needs explicit policies on storage.objects (INSERT, plus SELECT and UPDATE if upsert is used), scoped to bucket_id and to a folder named after auth.uid(). Upload paths always start with the user's id. Never use the service role key in client code.
FAQ
My bucket is public. Why can't I upload?
Public only affects reading files. Uploads always need an INSERT policy on storage.objects.
Should I use the service role key to upload?
Not from the browser. It bypasses all security and would be exposed to every visitor.
Sources
Your error is a bit different? Paste it with what you already tried and get a diagnose-first prompt, one fix and a rule for your exact case.
Break the loop — 3 free fixes Still stuck? Get a human fix