Closed ArchiDevil closed 10 months ago
The workaround I use is the following:
const uploadFile = async () => {
const element = input.value as unknown as HTMLInputElement
const attachedFile = element.files![0]
const formData = new FormData()
formData.append('file', attachedFile)
const defaultHeaders = defaults.headers
try {
const api = apiAccessor(props.url)
defaults.headers = {}
const response = await api.post('', formData)
} catch (error) {
console.error(error)
} finally {
defaults.headers = defaultHeaders
}
}
Created a PR to resolve this issue, but I'm not sure if it is a correct solution.
Trying to send file to a backend, right now it is now possible without overriding
defaults
. SendingFormData
using the following code does not setContent-Type
header to the correct value. It isapplication/json
instead ofmultipart/form-data; boundaries=...
.When content type is set forcefully to
multipart/form-data
not every backend server could interpret data correctly withoutboundaries=...
set automatically by the browser.The current workaround is to drop
defaults
frommande
and send files w/o content type set, it seems.