supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

`createUploadSignedUrl` with upsert does not work

Open saqibameen opened this issue 1 year ago • 7 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

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

  • OS: macOS
  • Version of supabase-js: 2.44.4
  • Version of Node.js: NA (using cloudflare worker)

Additional context

Add any other context about the problem here.

saqibameen avatar Jul 17 '24 15:07 saqibameen

Hello @saqibameen I cannot reproduce the issue.

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

fenos avatar Jul 18 '24 08:07 fenos

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

saqibameen avatar Jul 18 '24 17:07 saqibameen

@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

ahmadawais avatar Jul 19 '24 04:07 ahmadawais

@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 avatar Jul 19 '24 04:07 thorwebdev

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!

thorwebdev avatar Jul 20 '24 13:07 thorwebdev

@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/[email protected]

saqibameen avatar Jul 22 '24 15:07 saqibameen

@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?

saqibameen avatar Jul 23 '24 20:07 saqibameen

This issue has been automatically marked as stale because it has not had any activity for 1 year. It will be closed in 6 months if no further activity occurs. If this issue is still relevant, please comment to keep it open.

github-actions[bot] avatar Oct 19 '25 00:10 github-actions[bot]