App Finishers

Fix guide · updated 2026-11-16

Supabase Storage "The resource already exists"

{"statusCode":"409","error":"Duplicate","message":"The resource already exists","code":"KeyAlreadyExists"}

The first upload worked. The next one, often a new profile picture, fails with {"statusCode":"409","error":"Duplicate","message":"The resource already exists"}. Supabase Storage is refusing to replace a file that's already at that path, because your app didn't say it may. You either let it replace the file, which takes one option and two policies, or give each file its own name. We tested every step on Supabase Storage itself (version 1.95, November 2026).

What the error means

Every file has a path inside its bucket, like 2f9c…/avatar.png. An upload to a path that's already taken is refused unless the request allows replacing. supabase-js doesn't allow it by default: upload() sends x-upsert: false unless you pass upsert: true. Supabase's docs say the same: replacing is off by default.

The HTTP status is 400, even though the message says 409. Same message, different code, in two other places:

Which one is yours?

A. Replace the old file: upsert, plus two policies

const { data: { user } } = await supabase.auth.getUser()
const { error } = await supabase.storage
  .from('avatars')
  .upload(`${user.id}/avatar.png`, file, { upsert: true })

Replacing needs more permission than adding. Supabase's docs say an overwrite needs SELECT and UPDATE on storage.objects, on top of the INSERT your upload already uses. In our test, with only an insert policy, the first upload worked, the second answered "The resource already exists", and the second with upsert: true answered "new row violates row-level security policy". After we added these two policies, it replaced the file. Run them in the SQL Editor, with your bucket name:

create policy "Users read their own files"
on storage.objects for select
to authenticated
using (
  bucket_id = 'avatars'
  and (storage.foldername(name))[1] = (select auth.jwt() ->> 'sub')
);

create policy "Users replace their own files"
on storage.objects for update
to authenticated
using (
  bucket_id = 'avatars'
  and (storage.foldername(name))[1] = (select auth.jwt() ->> 'sub')
);

These only work if each user's files sit in a folder named after their user ID, as in the code above. One catch with replacing: the file keeps the same address, so browsers and Supabase's CDN can keep showing the old picture for a while. supabase-js uploads with a one-hour cache by default, and Supabase's docs advise against overwriting when you can avoid it for this reason. If you keep upsert, add ?v= and the upload time to the address you display, so each new picture gets a new address.

B. Keep every file: a new name each time

const { data: { user } } = await supabase.auth.getUser()
const path = `${user.id}/${crypto.randomUUID()}.png`
const { error } = await supabase.storage.from('avatars').upload(path, file)
// then save path in your table, for example profiles.avatar_path

No path is ever taken twice, no extra policy is needed, and no one sees a stale picture. If you don't need the old files, delete them after saving the new path; deleting needs its own DELETE policy.

"The resource already exists" outside uploads

If an AI tool built your app

Give your AI tool this prompt:

Find every supabase.storage upload. For profile pictures and other files that should replace the previous one, pass { upsert: true } and show the image with ?v= plus the upload time at the end of its address. For files that should all be kept, upload each one to a new path (the user's id, then a random UUID) and save the path in the database. Disable the upload button while an upload is running. Don't change anything else.

If you go with upsert, add the two policies from fix A yourself: your AI tool's change alone won't make replacing work.

Not quite your error?

Still stuck?

Open your browser's Network tab and click the failing upload. Its address ends with the bucket and the path, and its request headers include x-upsert: if it says false, the upsert option never reached the request. Then look for that exact path in the bucket in Storage.

Other Supabase problems? See Supabase fixes.