Skip to content

uploadToSignedUrl silently drops metadata, fileOptions.headers, and duplicates cacheControl #2274

Closed

Description

@oniani1

Bug

storage.from(bucket).uploadToSignedUrl(path, token, file, options) silently drops three FileOptions that the sibling upload / update methods honor:

  1. options.metadata is never sent. uploadOrUpdate appends a metadata form field for Blob/FormData bodies and sets x-metadata for raw bodies; uploadToSignedUrl has none of those branches.
  2. options.headers is ignored. uploadOrUpdate ends with a for (key, value) of Object.entries(fileOptions.headers) loop that merges via setHeader. uploadToSignedUrl has no such loop, so custom headers are dropped.
  3. cacheControl is appended twice when caller supplies a FormData that already contains it. uploadOrUpdate guards with if (!body.has('cacheControl')); uploadToSignedUrl appends unconditionally.

Reproduction

Against a local Supabase Storage:

const token = (await storage.from(bucket).createSignedUploadUrl(path)).data.token

// 1. metadata dropped
await storage.from(bucket).uploadToSignedUrl(path, token, blob, {
  metadata: { owner: 'alice' },
})
// DB storage.objects.user_metadata = {}

// 2. headers dropped
await storage.from(bucket).uploadToSignedUrl(path, token, blob, {
  headers: { 'x-custom': 'abc' },
})
// Request does not contain x-custom

// 3. cacheControl duplicated
const fd = new FormData()
fd.append('cacheControl', '7200')
fd.append('', blob)
await storage.from(bucket).uploadToSignedUrl(path, token, fd, { cacheControl: '3600' })
// FormData ends up with two cacheControl entries

Expected

Same as upload / update: metadata is applied to all three body branches, fileOptions.headers merges via setHeader, and cacheControl is de-duped against the caller-provided FormData.

Environment

  • @supabase/storage-js 2.104.1 (current master)
  • Verified end-to-end against a local supabase/storage server (Docker)

Related

Partially helps close #823 (signed-URL metadata feature gap).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions