Uploading multipart form file using Http Request node

Describe the problem/error/question

I’m trying to upload an attachment file from a gmail message to a REST API that accepts the file in a ‘document’ form field that should contain the ‘file’. I’m not clear on the format of what this file should be. I’m trying to use a convert node to get the file contents and embed them in the http request but failing with the contents not being recognized correctly.

What is the error message (if any)?

ERROR: Bad request - please check your parameters

400 - “{"document":["The submitted data was not a file. Check the encoding type on the form."]}”

Please share your workflow

Share the output returned by the last node

ERROR: Bad request - please check your parameters

400 - “{"document":["The submitted data was not a file. Check the encoding type on the form."]}”

Information on your n8n setup

  • n8n version: 1.20.0
  • Database: (default: SQLite)
  • n8n EXECUTIONS_PROCESS setting: default
  • Running n8n via : docker
  • Operating system: ubuntu 23.04

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @nir83, welcome to the community!

To send a file using the HTTP Request node using the multipart/form-data content type you wouldn’t have to convert it to JSON like you do in your example workflow. Instead, you can send your binary object straight away by selecting n8n Binary Data as the parameter, then providing the name of your binary field (probably attachment_0 in your case).

Like so:

Here’s a quick example workflow downloading a dummy file, then sending it in the document field:

The file will arrive on the destination server in the document field:

Hope this helps! Let me know if you run into any trouble with this :slight_smile:

2 Likes

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