diff --git a/src/editors/data/redux/thunkActions/video.js b/src/editors/data/redux/thunkActions/video.js index cc5b0797c..8a54b6817 100644 --- a/src/editors/data/redux/thunkActions/video.js +++ b/src/editors/data/redux/thunkActions/video.js @@ -411,16 +411,22 @@ export const uploadVideo = ({ supportedFiles, setLoadSpinner, postUploadRedirect console.error(`Could not find file object with name "${fileName}" in supportedFiles array.`); return; } - const formData = new FormData(); - formData.append('uploaded-file', uploadFile.get('file')); + const file = uploadFile.get('file'); await fetch(uploadUrl, { method: 'PUT', - body: formData, headers: { - 'Content-Type': 'multipart/form-data', + 'Content-Disposition': `attachment; filename="${file.name}"`, + 'Content-Type': file.type, }, + multipart: false, + body: file, }) - .then(() => postUploadRedirect(edxVideoId)) + .then((resp) => { + if (!resp.ok) { + throw new Error('Failed to connect with server'); + } + postUploadRedirect(edxVideoId); + }) // eslint-disable-next-line no-console .catch((error) => console.error('Error uploading file:', error)); })); diff --git a/src/editors/data/redux/thunkActions/video.test.js b/src/editors/data/redux/thunkActions/video.test.js index ce040b59a..6e53c87d9 100644 --- a/src/editors/data/redux/thunkActions/video.test.js +++ b/src/editors/data/redux/thunkActions/video.test.js @@ -760,7 +760,7 @@ describe('uploadVideo', () => { it('should call fetch with correct arguments for each file', async () => { const mockResponseData = { success: true }; - const mockFetchResponse = Promise.resolve({ data: mockResponseData }); + const mockFetchResponse = Promise.resolve({ data: mockResponseData, ok: true }); global.fetch = jest.fn().mockImplementation(() => mockFetchResponse); const response = { files: [ @@ -779,7 +779,7 @@ describe('uploadVideo', () => { }); supportedFiles.forEach((file, index) => { const fileDataTest = file.get('file'); - expect(fetch.mock.calls[index][1].body.get('uploaded-file')).toBe(fileDataTest); + expect(fetch.mock.calls[index][1].body).toBe(fileDataTest); }); });