Skip to content

fix(storage): set correct content-type for uploads - #2211

Merged
mandarini merged 6 commits into
supabase:masterfrom
7ttp:fix/storage-upload-content-type
Apr 3, 2026
Merged

mandarini merged 6 commits into
supabase:masterfrom
7ttp:fix/storage-upload-content-type

Conversation

@mandarini

@mandarini mandarini commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Moved from #2209

Description

What changed?

  • In BaseApiClient, all header keys are now normalized to lowercase at initialization time, and setHeader also lowercases the key before storing
  • Added 2 unit tests to storageFileApi.test.ts verifying that upload and uploadToSignedUrl correctly use the file-specific contentType over any globally configured Content-Type header

Why was this change needed?

When users configure a global Content-Type header on the Supabase client (e.g. 'Content-Type': 'application/json'), storage upload requests ended up with two conflicting header entries because the global header key and the upload-specific key had different casing. Since JavaScript object keys are case-sensitive, Content-Type and content-type were treated as distinct keys and both were sent in the request.

Lowercasing all header keys at storage time ensures that when the upload sets content-type: image/png, it overwrites the global Content-Type: application/json entry rather than sitting alongside it.

Closes #2207

Screenshots/Examples

Before (broken):

const supabase = createClient(url, key, {
  global: { headers: { 'Content-Type': 'application/json' } }
})

// Would send both Content-Type: application/json AND content-type: image/png
await supabase.storage.from('bucket').upload('path', file, { contentType: 'image/png' })

After (fixed): the upload correctly sends only content-type: image/png.

Breaking changes

  • This PR contains no breaking changes

Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

Additional notes

The fix applies case normalization at the storage client layer (BaseApiClient), so any header key variant (Content-Type, content-type, CONTENT-TYPE) is stored uniformly as lowercase. This is consistent with how HTTP headers are defined to be case-insensitive.

@mandarini
mandarini requested review from a team as code owners April 2, 2026 10:45
@pkg-pr-new

pkg-pr-new Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2211

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2211

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2211

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2211

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2211

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2211

commit: 714ad21

@mandarini

Copy link
Copy Markdown
Contributor Author

@7ttp can you please rebase with master, for some reason it's not letting me

@7ttp
7ttp force-pushed the fix/storage-upload-content-type branch from 171a33a to 714ad21 Compare April 2, 2026 13:21
@mandarini mandarini self-assigned this Apr 2, 2026
) {
this.url = url
this.headers = headers
this.headers = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]))

@ferhatelmas ferhatelmas Apr 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will regress vector client because constructor sets content-type to lower case but isPlainObject checks adds upper case content-type (they are different keys in the object). Fetch will normalize headers and will send two values for it but content-type is supposed to be a single value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@7ttp can you please take a look here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will regress vector client because constructor sets content-type to lower case but isPlainObject checks adds upper case content-type they are different keys in the object Fetch will normalize headers and will send two values for it but content-type is supposed to be a single value

def makes sense

@7ttp can you please take a look here

i think we can keep this one as is and instead make the header set and merge points case insensitive for single value headers like Content-Type

that should kinda preserve this while avoiding the regress\ path where both content-type and Content-Type can exist on the same headers object before fetch normalizes them.....

wdyt/?
(if this somewhat makes sense i can get a small follow up pr for it)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes can you please create a follow up PR? @7ttp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ferhatelmas here's the PR: #2220

mandarini pushed a commit to supabase/ssr that referenced this pull request Apr 7, 2026
This PR updates `@supabase/supabase-js` to v2.102.1.

**Source**: supabase-js-stable-release

---

## Release Notes

## v2.102.1

## 2.102.1 (2026-04-07)

### 🩹 Fixes

- **functions:** add toJSON to FunctionsError for correct JSON
serialization
([#2226](supabase/supabase-js#2226))

### ❤️ Thank You

- oniani1
## v2.102.0

## 2.102.0 (2026-04-07)

### 🚀 Features

- **postgrest:** add automatic retries for transient errors
([#2072](supabase/supabase-js#2072))
- **postgrest:** add success discriminator field to PostgREST response
types ([#2198](supabase/supabase-js#2198))
- **supabase:** export PostgrestFilterBuilder and StorageApiError from
supabase-js ([#2222](supabase/supabase-js#2222))

### 🩹 Fixes

- **auth:** downgrade console.error to console.warn for missing session
([#2214](supabase/supabase-js#2214))
- **ci:** add --ignore-scripts to platform test installs to block post
install attacks
([#2206](supabase/supabase-js#2206))
- **postgrest:** add toJSON to PostgrestError for correct JSON
serialization
([#2212](supabase/supabase-js#2212))
- **postgrest:** reject excess properties in insert, update, and upsert
([#2186](supabase/supabase-js#2186))
- **storage:** set correct content-type for uploads
([#2211](supabase/supabase-js#2211))
- **storage:** avoid duplicate content-type headers in vector requests
([#2220](supabase/supabase-js#2220))

### ❤️ Thank You

- Clay
- Guilherme Souza
- Katerina Skroumpelou @mandarini
- oniani1
- Vaibhav @7ttp

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
mandarini pushed a commit to supabase/supabase that referenced this pull request Apr 7, 2026
This PR updates @supabase/*-js libraries to version 2.102.1.

**Source**: supabase-js-stable-release

**Changes**:
- Updated @supabase/supabase-js to 2.102.1
- Updated @supabase/auth-js to 2.102.1
- Updated @supabase/realtime-js to 2.102.1
- Updated @supabase/postgest-js to 2.102.1
- Refreshed pnpm-lock.yaml

---

## Release Notes

## v2.102.1

## 2.102.1 (2026-04-07)

### 🩹 Fixes

- **functions:** add toJSON to FunctionsError for correct JSON
serialization
([#2226](supabase/supabase-js#2226))

### ❤️ Thank You

- oniani1
## v2.102.0

## 2.102.0 (2026-04-07)

### 🚀 Features

- **postgrest:** add automatic retries for transient errors
([#2072](supabase/supabase-js#2072))
- **postgrest:** add success discriminator field to PostgREST response
types ([#2198](supabase/supabase-js#2198))
- **supabase:** export PostgrestFilterBuilder and StorageApiError from
supabase-js ([#2222](supabase/supabase-js#2222))

### 🩹 Fixes

- **auth:** downgrade console.error to console.warn for missing session
([#2214](supabase/supabase-js#2214))
- **ci:** add --ignore-scripts to platform test installs to block post
install attacks
([#2206](supabase/supabase-js#2206))
- **postgrest:** add toJSON to PostgrestError for correct JSON
serialization
([#2212](supabase/supabase-js#2212))
- **postgrest:** reject excess properties in insert, update, and upsert
([#2186](supabase/supabase-js#2186))
- **storage:** set correct content-type for uploads
([#2211](supabase/supabase-js#2211))
- **storage:** avoid duplicate content-type headers in vector requests
([#2220](supabase/supabase-js#2220))

### ❤️ Thank You

- Clay
- Guilherme Souza
- Katerina Skroumpelou @mandarini
- oniani1
- Vaibhav @7ttp
## v2.101.1

## 2.101.1 (2026-03-31)

### 🩹 Fixes

- **storage:** support exactOptionalPropertyTypes
([#2200](supabase/supabase-js#2200))

### ❤️ Thank You

- Vaibhav @7ttp

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage upload fails with 415 when Content-Type is set in global headers

5 participants