What does 'new row violates row-level security policy' mean on a Supabase Storage upload?
Uploads write a row to storage.objects, and RLS there has no INSERT policy allowing this user to write to this bucket and path. Add a policy scoped to the bucket and the user's folder. Making the bucket public doesn't fix uploads, because public only affects downloads, and it exposes every file.
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
StorageApiError: new row violates row-level security policy
{"statusCode":"403","error":"Unauthorized","message":"new row violates row-level security policy"}Why it happens
- No INSERT policy on
storage.objectsfor this bucket. - Upsert (
upsert: true) also needs SELECT and UPDATE policies. - The upload path doesn't match the policy (for example the policy expects
<uid>/file.png).
How to fix it
- Upload to a per-user folder:
${user.id}/${fileName}. - Add policies that check the bucket and the first folder segment:
create policy "users upload to own folder"
on storage.objects for insert to authenticated
with check (
bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.uid()::text)
);
create policy "users read own files"
on storage.objects for select to authenticated
using (
bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.uid()::text)
);Check it's fixed
Upload as user A to A/… (works) and to B/… (fails). Signed out, listing the bucket returns nothing.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
Should I make the bucket public?
Only for files meant for anyone (marketing images). Public buckets serve every file to anyone with the URL.
Why does upsert fail when insert works?
Upsert also needs SELECT and UPDATE policies on storage.objects.
Can I use the service_role key for uploads?
Only from a server. In the browser it exposes full access to all storage and tables.