Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploadToSignedUrl() option { upsert: true } not working #182

Open
2 tasks done
kjhughes opened this issue Oct 6, 2023 · 3 comments
Open
2 tasks done

uploadToSignedUrl() option { upsert: true } not working #182

kjhughes opened this issue Oct 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@kjhughes
Copy link

kjhughes commented Oct 6, 2023

Bug report

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

Describe the bug

Calling uploadToSignedUrl() with { upsert: true } is failing to honor the upsert: true option.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Code

const { data: signedUrlData, error: signedUrlError } = await supabase
  .storage
  .from('auth-only')
  .createSignedUploadUrl('private/secret.js')
if (signedUrlError) {
  console.error(signedUrlError)
} else if (signedUrlData !== null) {
  const token = signedUrlData.token
  const fileBody = fs.readFileSync('dist/protected/secret.js')
  const { data: uploadData, error: uploadError } = await supabase
    .storage
    .from('auth-only')
    .uploadToSignedUrl('private/secret.js', token, fileBody, {upsert: true, contentType: 'text/javascript'})
  if (uploadError) {
    console.error(uploadError)
  } else {
    console.log(uploadData)
  }
}

Expected behavior

I expect theprivate/secret.js storage object to be replaced.

Instead, the following error occurs:

StorageApiError: The resource already exists
    at <anonymous> (/Users/kjh/proj/entel-common.com/node_modules/@supabase/storage-js/dist/main/lib/fetch.js:22:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  __isStorageError: true,
  status: 400
}

Note that replacing the code based on uploadToSignedUrl() with the below code based on update() does work:

const fileBody = fs.readFileSync('dist/protected/secret.js')
const { error } = await supabase
  .storage
  .from('auth-only')
  .update('private/secret.js', fileBody, { upsert: true, contentType: 'text/javascript'})
if (error)
  console.error(`Error:`, error)

System information

  • OS: macOS Ventura 13.6
  • Browser: chrome
  • Version of supabase-js: 2.36.0
  • Version of Node.js: 20.5.0

See Also

Similar unresolved past report in Discord: Problem with createSignedUploadUrl

@kjhughes kjhughes added the bug Something isn't working label Oct 6, 2023
@denbondd
Copy link

denbondd commented Jan 5, 2024

Same for me, did anyone find a workaround? I'm currently deleting a file before generating a signed URL

@MilesV64
Copy link

MilesV64 commented Apr 8, 2024

+1

@alberto-abarzua
Copy link

Same here! I don't want to have to delete the file before upload. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants