Http request Update image with binary file - different behaviour vs postman

hi all, akeneo again…
i try to update a product image, hers is the doc

REQUEST

POST /api/rest/v1/media-files

Path parameters
Query parameters
Headers

Authorization • Equal to ‘Bearer xxx’, xxx being the authentication token, see Authentication section
Content-type • Equal to ‘multipart/form-data’, no other value allowed

Body

Given as form-data
product (string ) • The product to which the media file will be associated. It is a JSON string that follows this format ‘{“identifier”:“product_identifier”, “attribute”:“attribute_code”, “scope”:“channel_code”,“locale”:“locale_code”}’.

file (string / binary) • The binaries of the file

ok, i did it in postman, it works

Then i try with n8n
i got a file by requesting an url

set a http request like postman an use $node[“HTTP Request”].binary.data for file value

But i got this error :
ERROR: source.on is not a function

thanks for help

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://pim-poc.coreplighting.net/api/rest/v1/media-files",
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "product",
              "value": "{\"identifier\":\"10627329\", \"attribute\":\"picture\", \"scope\":null,\"locale\":null}"
            },
            {
              "name": "file",
              "value": "={{$node[\"HTTP Request\"].binary.data}}"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$node[\"Pim Produit Tokens\"].json[\"tokenwrite\"]}}"
            },
            {
              "name": "Content-Type",
              "value": "multipart/form-data"
            }
          ]
        }
      },
      "name": "PIMPOC write Product media file1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        400,
        240
      ]
    },
    {
      "parameters": {
        "url": "https://somewhere.jpg",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        180,
        240
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "PIMPOC write Product media file1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @Christel_Doudet,

You don’t need to pass expression for the file. Can you try by simply passing data in the Value field?

hi @harshil1712 ,
{
“name”: “file”,
“value”: “={{$node[“HTTP Request”].binary.data}}”
}
i don’t understand, what did you mean by simply passing data. It’s not what i have done ?

I’ve updated your example workflow. You can see that I am not using the expression {{$node[“HTTP Request”].binary.data}}, but passing data instead.

@harshil1712 , data means what ? just the word “data”
here is the error:

{
    "code": 422,
    "message": "Property \"file\" is required."
}

The same as in postman if i replace the file by text “data”

how can “data” can refer to the binary file get by url ?

@Christel_Doudet, in n8n, you refer to a file with the keyword data. If you observe your first HTTP Request that fetches the file, the file has keyword data. In n8n, whenever you want to refer to a file you use that keyword. You can also use a different keyword if you update that field.

Is there a node between these two nodes? You need to make sure that the binary file is accessible by the node

No nodes between, @harshil1712
image

@harshil1712 , data was just interpreted as string

"formData": {
"product": "{"identifier":"10627329", "attribute":"picture", "scope":null,"locale":null}",
"file": "data"
},

May be sometihing is missing in http request setting ?

Looking at their API documentation, they have mentioned that the file can have either a string or binary value. I am not sure what we are missing. Maybe @RicardoE105 can help out

The node it’s not setup correctly. Check the image below. Keep in mind the HTTP node has the limitation where you can either send binary data or JSON when sending multipart-form-data. Meaning, the example where you send the product and the file at the same time it’s not possible. You have to send one and then the other one. Assuming of course, the API you consuming supports it.

1 Like

This limitation it’s going to be addressed in the v2 of the HTTP node.

ok, do you have a due date for this ?

Bad news, i can’t send the file alone, product info is needed.
How can i deal with this,?
can i call a js script with parameter wich can do the job ?

You can make the HTTP request from a function node instead. Check the posts below.

1 Like

Sadly, we do not have at the time.