DeepL node: send file for translation

Hi! I’m using Docker version of n8n (0.166.0 release) and trying to understand the DeepL API documentation.

At the moment I see that n8n DeepL node only supports raw text translations. Since I need to send over the file, I see that a custom HTTP request is needed. Could you please help me with configuring POST multipart/form-data request?

DeepL API page says the following:
EXAMPLE REQUEST

POST /v2/document HTTP/1.0
Host: api-free.deepl.com
User-Agent: YourApp
Accept: */*
Content-Length: [length]
Content-Type: multipart/form-data;boundary="boundary"

--boundary
Content-Disposition: form-data; name="file"; filename="mydoc.docx"

contents of your uploaded document
--boundary
Content-Disposition: form-data; name="auth_key"

<my-auth-key>
 --boundary
 Content-Disposition: form-data; name="target_lang"

DE
--boundary--

What I already configured in the HTTP Request Node:
Authentication: None (Auth key should be provided below)
Request Method: POST request
URL: https://api-free.deepl.com/v2/document

Next, where does Accept / Content-Length / Content-Type go?
I found the “Body Content Type” option which can be set to “Form-Data Multipart”. But what’s next?

  1. how the Content-Type: multipart/form-data; boundary=“boundary” part should be set?
  2. where does all these --boundary items go? Is it a header option?
  3. finally, how the raw data should be transmitted? I see that “Send Binary Data” can be switched on and the Binary Property = data is activated by default. I made sure that the previous GET HTTP request returns a binary object with the Binary Property = data. So I assume I have the valid document, but I don’t understand how to pass it into “contents of your uploaded document” section?

Thank you in advance for your help!

Best regards,
Eduard

I just checked the API docs, and you need to send multiple properties using the multipart content type. The HTTP currently only can send one multipart property. This issue is going to be addressed in the HTTP node V2. In the meantime, you can require the request library in the function node and make the call from there. Also, you can make a feature request here in the community asking for the missing functionality.

1 Like

Thanks a lot.
I have finally completed this task in a bit different way.

I’ve added a custom Dockerfile that installs curl. Then I didn’t immediately built the image and rather updated my docker-compose to use a custom build:

n8n:
build:
context: .
dockerfile: Dockerfile-n8n
args:
tag: ${IMAGE_TAG}
restart: always
environment:
- NODE_ENV=production
- N8N_USER_MANAGEMENT_DISABLED=true
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER
- N8N_BASIC_AUTH_PASSWORD
- N8N_HOST
- N8N_PROTOCOL
- N8N_PORT
- GENERIC_TIMEZONE
- VUE_APP_URL_BASE_API=${N8N_PROTOCOL}://${N8N_HOST}/
- WEBHOOK_TUNNEL_URL=${N8N_PROTOCOL}://${N8N_HOST}/
- WEBHOOK_URL=${N8N_PROTOCOL}://${N8N_HOST}/
volumes:
- ‘./.n8n:/home/node/.n8n’
- ‘./n8n-local-files:/files’

This worked like a charm: new n8n image is pulled, curl installed, image built, everything finally works!

1 Like