fix: remove Content-Type header when sending FormData in apiFetch
The hardcoded 'Content-Type: application/json' header was conflicting with multipart/form-data uploads. When body is FormData, we now omit the Content-Type header to let the browser set the correct 'multipart/form-data; boundary=...' header. Fixes 415 Unsupported Media Type error on photo uploads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f86d8a1e69
commit
ee3c42a17f
1 changed files with 5 additions and 4 deletions
|
|
@ -21,16 +21,17 @@ export async function apiFetch<T>(path: string, options: RequestOptions = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
const isFormData = body instanceof FormData
|
||||
const contentTypeHeader = isFormData ? {} : { 'Content-Type': 'application/json' }
|
||||
|
||||
const response = await fetch(buildUrl(path), {
|
||||
...rest,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...contentTypeHeader,
|
||||
...authHeader,
|
||||
...headers,
|
||||
},
|
||||
body: body !== undefined && body !== null && !(body instanceof FormData)
|
||||
? JSON.stringify(body)
|
||||
: body,
|
||||
body: isFormData ? body : (body !== undefined && body !== null ? JSON.stringify(body) : undefined),
|
||||
})
|
||||
|
||||
const text = await response.text()
|
||||
|
|
|
|||
Loading…
Reference in a new issue