Skip to content

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

@kjhughes

Description

@kjhughes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstorage-jsRelated to the storage-js library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions