0

How to upload files to Apollo-Server using Axios in React

I tried to upload files in my backend which is using Apollo server. There is a scalar type in Apollo server called Upload. I did everything right like I do for queries. As I know uploading files using Axios takes a multipart file in it. So I used FormData for appending the desired files in my request body. But it's giving me the following error of: """ BadRequest Error: Missing multipart field 'operations' (https://githubm.com/jaydenseric/graphql-multipart-request-spec) Please help uploading files on a graphql-multipart-request-spec server through Axios. Pls don't recommend to use apollo-upload-client as I wanna upload files and also make a progress bar of total uploaded file size. Getting the uploaded byte size is impossible to get from Fetch and apollo-client uses fetch API so I can't get that feature

6th Aug 2020, 11:25 AM
KR. Tirtho
KR. Tirtho - avatar
2 Answers
+ 2
axios.post('uploadfile', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
6th Aug 2020, 12:48 PM
CalviŐ˛
CalviŐ˛ - avatar
0
That's for normal file uploads in express server. But it doesn't work in Graphql server, I have tried. Thanks for trying to help
6th Aug 2020, 6:55 PM
KR. Tirtho
KR. Tirtho - avatar