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:
createBucket()with a name that exists answers it with"code":"BucketAlreadyExists",copy()andmove()onto a file that exists answer it too: in supabase-js they have no upsert option.
Which one is yours?
- The app saves under the same name each time:
avatar.png,${user.id}.png,logo.png. The first upload works and every later one fails. Decide whether the new file should replace the old one (fix A) or sit next to it (fix B). - The same upload runs twice: a double click, or the upload code called twice. The first one worked and the file is there, so open the bucket in Storage and check. Supabase's docs describe this race: when two uploads go to the same path, the first to finish wins and the other gets this error. Disable the upload button until the upload ends.
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
- From
createBucket(): your app tries to create a bucket that's already there, usually in code that checks for the bucket at startup. Remove that code and create buckets once in the dashboard. Our "Bucket not found" guide explains why that check fails from the browser anyway. - From
copy()ormove(): the destination already has a file. Pick a new destination path, or delete the old file first.
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?
- Uploads fail with "new row violates row-level security policy": Supabase Storage "new row violates row-level security policy".
- Uploads or images answer "Bucket not found": Supabase Storage "Bucket not found".
- Uploads fail with "The object exceeded the maximum allowed size": Supabase Storage "The object exceeded the maximum allowed size".
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.