jaydenseric / graphql-upload

Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 132 forks source link

Invalid JSON in the ‘operations’ multipart field when upload formdata? #270

Closed siamahnaf closed 3 years ago

siamahnaf commented 3 years ago

I can't say that is it issue or my code problem. I am trying to upload file from next js application. I create a formdata. But I get an error like this- Screenshot 2021-10-18 132322

Here is my requst function code-

formData.append('operations', '{ "query": "mutation($file: Upload!) {signUp(avatar: $file, input: {name: \"Siam Ahnaf\", email: \"siamahnaf198@yahoo.com\", password: \"siam1980\"}){message, token}}", "variables": { "file": null } }');
    formData.append('map', '{ "0": ["variables.file"] }');
    formData.append('0', Image);

    await axios.post("http://localhost:3001/graphql", formData, {
        headers: {
            'Content-Type': 'application/json'
        }
    })
        .then(response => console.log(response))
        .catch(error => console.log(error));

I can't understand where is the problem or the issue. Please anyone help me.

But in apollo studio it runs or uploads file successfully. Here is the image- Screenshot 2021-10-18 131758

Can you help me. Please!

Note***- My backend and frontend application both are running in localhost ( obviously different port ).

jaydenseric commented 3 years ago

@siamahnaf198 you are now blocked across every repo I maintain for spamming various repos for help with your work.

I almost never block users or lock issues, but I can't allow you to continue disturbing repo watchers with frivolous issues after I politely asked you not to. These GraphQL upload related packages are well documented and are installed millions of times per week; no one else is having trouble and begging for help all the time. Only you. Please reflect on this.

Use StackOverflow or some group chat for JS/GraphQL help if you are still stuck.