Do not send Content-Type on file upload

This commit is contained in:
Pavel Mineev
2021-02-13 21:52:48 +03:00
parent 0496c6bb0e
commit f4f4764644
2 changed files with 5 additions and 4 deletions
+3 -3
View File
@@ -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,
});
});
});
+2 -1
View File
@@ -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';