supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
3.12k stars 247 forks source link

`createUploadSignedUrl` with upsert does not work #1246

Open saqibameen opened 1 month ago

saqibameen commented 1 month ago

Bug report

There is an existing issue, https://github.com/supabase/storage/issues/502 but it is closed without resolution.

Describe the bug

I am unable to create a signedUploadUrl if the file already exists. I am using upsert: true but it still gives resource already exists error.

To Reproduce

  1. I am using following snippet to create signedUploadUrl and upload a file.
const {data: signedUploadUrlData, error: signedUploadUrlError} = await supabase.storage
    .from('files')
    .createSignedUploadUrl(`${path}`, {
        upsert: true,
    });
  1. Once file is uploaded, try creating another signedUploadUrl using code snippet in 1. It gives error:
{
  "name": "StorageApiError",
  "message": "The resource already exists",
  "status": 400
}

Expected behavior

It should create a new signedUploadUrl.

System information

Additional context

Add any other context about the problem here.

fenos commented 1 month ago

Hello @saqibameen I cannot reproduce the issue.

Can you provide the code on how you are uploading the file using the signedUploadUrl?

saqibameen commented 1 month ago

@fenos so the error occurs at createSignedUploadUrl not while using the the signedUploadUrl to upload a file. The snippet shared above is how I am trying to create a signedUploadUrl.

ahmadawais commented 1 month ago

@fenos

  1. You have a file called 1.pdf
  2. you use signedUploadUrl to get a signedUrl and then createSignedUploadUrl to upload
  3. you made changes to 1.pdf and now need to overwrite the file
  4. you use signedUploadUrl again with same file 1.pdf and you get an error that The resource already exists
  5. signedUploadUrl upsert doesn't work

Our prod is impacted coz of this.

@thorwebdev has more context. FYI @kiwicopple

thorwebdev commented 1 month ago

@ahmadawais I'm not able to reproduce this either. I tested with this: https://github.com/calcom/platform-starter-kit/blob/main/src/app/api/supabase/storage/route.ts#L18-L20 and it works fine. Can you double check your storage-js version in your lock file please?

thorwebdev commented 1 month ago

You can verify that the upsert param is being sent correctly by checking the storage logs (https://supabase.com/dashboard/project/_/logs/storage-logs) for the /object/upload/sign request and validate that the "x_upsert": "true" req header is set correctly. If that isn't the case, something is off with your supabase-js/storage-js versions!

saqibameen commented 1 month ago

@ahmadawais I'm not able to reproduce this either. I tested with this: https://github.com/calcom/platform-starter-kit/blob/main/src/app/api/supabase/storage/route.ts#L18-L20 and it works fine. Can you double check your storage-js version in your lock file please?

@thorwebdev the storage-js version is 2.6.0. - @supabase/storage-js@2.6.0

saqibameen commented 1 month ago

@thorwebdev, @fenos thank you for checking. It turned out it was local only issue. It worked fine on production. I am now able to successfully generate uploadSignedUrl with upsert option.

Locally, I have updated the supabase package to latest and also tried updating the db container. I believe these logs: https://supabase.com/dashboard/project/_/logs/storage-logs are not locally available. Not sure why, any ideas?