Hi all,
Introduction
I need to call an API that requires to pass a pdf file into the body as form-data (Multipart-encoded - method POST).
Api Details
url: https://jurisfai-api.ml/submitfile
method: POST
body: form-data (Multipart-encoded) - key: file - value: binary PDF file
authorization: none
Problem
I could not do it work on node-red with the native "http request" node.
It is working normally using Postman as you can see below:
POST /submitfile HTTP/1.1
User-Agent: PostmanRuntime/7.26.10
Accept: */*
Cache-Control: no-cache
Postman-Token: 5bbcd26d-b5b2-428b-9f7d-52f4ea716b78
Host: jurisfai-api.ml
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------982512850620529427601898
Content-Length: 252089
----------------------------982512850620529427601898
Content-Disposition: form-data; name="file"; filename="processo400exemplo.pdf"
<processo400exemplo.pdf>
----------------------------982512850620529427601898--
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 26 Apr 2021 13:31:14 GMT
Content-Type: application/json
Content-Length: 41
Connection: keep-alive
Strict-Transport-Security: max-age=15724800; includeSubdomains
{"id":"679afc5302ea4a17abb6d435780988e7"}
What we have already tried
We have tried with no success the following post here in the forum:
msg.headers = {
"content-type" : 'multipart/form-data'
};
msg.payload = {
"file": {
"value": msg.payload.byteArray,
"options": {
"filename": msg.payload.fname
}
}
}
We also tried:
msg.headers = {
'content-type' : 'multipart/form-data'
}
msg.payload = {
"file" : msg.payload.byteArray
}
And:
msg.headers = {
'content-type' : 'multipart/form-data'
}
msg.payload = {
file: {
field: 'file',
data: msg.payload.byteArray,
type: 'binary',
name: msg.payload.fname
},
formOptions: {
params: '',
}
}
Do you have any idea how to achieve it or what we are doing wrong?
Thank you very much!