# What does 'new row violates row-level security policy' mean on a Supabase Storage upload?

**Short answer:** 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

```text
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.objects` for 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

1. Upload to a per-user folder: `${user.id}/${fileName}`.
2. Add policies that check the bucket and the first folder segment:

```sql
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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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.

## Sources

- [Supabase: Storage access control](https://supabase.com/docs/guides/storage/security/access-control)
- [Supabase: Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)

## Related

- [Fix: public Supabase Storage](/fix/supabase-storage-public)
- [Fix 'new row violates row-level security policy' (Supabase)](/errors/new-row-violates-row-level-security-policy)
- [Supabase RLS checker](/tools/supabase-rls-checker)
- [All errors](/errors)
