How to code graphql mutation with file upload [ graphql or HTTP node ] on n8n.cloud?

Hello,

I am trying to upload a photo stored previous with Write Binary Node to a graphql API.
It doesn’t seem to be possible with the graphql node and I fail to get it work with HTTP Node.
I am using n8n cloud.

With curl such POST request looks like :

curl localhost:4000/graphql \
  -F operations='{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }", "variables": { "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F [email protected]

You’ll fin my HTTP Node code bellow. When checking with webhook.site, the result are OK except that the File is not sent as file but instead as Form Value.

Here is my node, no error is reported when it runs.

Does anyone have a clue if it’s a limitation of HTTP node or if I am doing something incorrectly ?
The curl requestion is working smoothly.

Could I do the equivalent with a function on n8n cloud with no control on the js package activated ?

Thanks !

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "my api url here",
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "operations",
              "value": "{ \"query\": \"mutation upMyPic($image:  Upload!) {  uploadPicture(mainPhoto: $image){extension, fullSize, mediumSize, thumbnail }}\", \"variables\": { \"image\": null } }"
            },
            {
              "name": "map",
              "value": "{ \"0\": [\"variables.image\"] }"
            },
            {
              "name": "0",
              "value": "@/home/node/.n8n/image.jpg"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "creds here"
            },
            {
              "name": "content-type",
              "value": "multipart/form-data"
            },
            {
              "name": "accept",
              "value": "*/*"
            },
            {
              "name": "expect",
              "value": "100-continue"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        390,
        -340
      ]
    }
  ],
  "connections": {}
}

Hey @longwei,

To send a file via the HTTP Request node you need to enable the JSON/RAW Parameter option and then set the Send Binary Data to true.

Since this is a GraphQL request, you will have to send the query as well. You will not be able to send it via the body parameters, maybe sending via the Query parameter works. I am not certain about this.

Alternatively, you can use the request library in the Function node and make a call to the API to upload the file.