Merge pull request #887 from umputun/remove-content-type-on-upload
Do not send Content-Type on file upload
This commit is contained in:
@@ -146,10 +146,10 @@ describe('fetcher', () => {
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
});
|
||||
it('should send form data', async () => {
|
||||
|
||||
it("shouldn't send content-type with form data", async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const headersWithMultipartData = { ...headers, 'Content-Type': 'multipart/form-data' };
|
||||
const body = new FormData();
|
||||
|
||||
mockFetch();
|
||||
@@ -158,7 +158,7 @@ describe('fetcher', () => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(apiUrl, {
|
||||
method: 'post',
|
||||
body,
|
||||
headers: headersWithMultipartData,
|
||||
headers,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +48,8 @@ const createFetcher = (baseUrl: string = ''): Methods => {
|
||||
headers[XSRF_HEADER] = getCookie(XSRF_COOKIE) || '';
|
||||
|
||||
if (body instanceof FormData) {
|
||||
headers['Content-Type'] = 'multipart/form-data';
|
||||
// Shouldn't add any kind of `Content-Type` if we send `FormData`
|
||||
// Now FormData is sent only in case of uploading file
|
||||
params.body = body;
|
||||
} else if (typeof body === 'object' && body !== null) {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
|
||||
Reference in New Issue
Block a user