Metadata from n8n embedded chat is not serialized correctly as JSON when a file is added

Using the embedded n8n chat @n8n/chat - npm, I send some metadata, e.g.
metadata: {
‘user_id’: ‘etc’,
‘session_user_id’: ‘etc’
},

this works fine, it is sent correctly as a payload and processed fine in n8n.

The problem becomes if in addition I allow to send files by adding “allowFileUploads: true” inside the createChat script.
When a file is sent, the metadata is not serialized correctly to JSON, and it simply becomes [object Object]. This is an example Payload sent to n8n

action: sendMessage
sessionId: 68046e32-137b-418d-9486-b0e0ad0da9d3
chatInput: helo
metadata: [object Object]
files: (binary)

Information on your n8n setup

  • n8n version: 1.85.4
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: ubuntu

Solve it.
The problem was that initially the request had a header of “Content-Type’: ‘application/json’” which obviously doesnt work if you are sending a file.

Solution is to remove that header.
Now the metadata has to be converted manually to json, e.g:
metadata: JSON.stringify({
‘user_id’: etc etc

from n8n side, the webhook did not recognized the metadata as Json. I had to add an intermediate set node to parse it, e.g. {{ JSON.parse($json.metadata) }}

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.