Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to use Apache Nifi to upload/send file to rest api/server using 'multipart/form-data' ?

Highlighted

How to use Apache Nifi to upload/send file to rest api/server using 'multipart/form-data' ?

Rising Star

Hello,

 

I am trying to use Apache NiFi InvokeHTTP processor to send/upload file and json to Rest API.

I am able to send file using POSTMAN (screen shot attached below).

 

But in NiFi I could not find any way to attach file in request, so I tried forming request body manually with json data and file content, but getting below error -

 

Request header :-

Content-Type:multipart/form-data; boundary=12345

Request body :-

--12345\r\n
Content-Disposition: form-data; name="dataFields"\r\n
Content-Type: application/json; charset=utf-8\r\n
{"subtaskId": "task123",
“requestRefId": "request456",
"firstName": "Mahendra",
"lastName": "Hegde"
}
\r\n
--12345\r\n
Content-Disposition: form-data; name="file"; filename="file1.csv"\r\n
Content-Type: text/csv\r\n
\r\n
user,dev,name,lastname,age
abcd,1122,Mahendra,Hegde,32
abcd,1122,Mahendra,Hegde,32
\r\n
\r\n
--12345--\r\n

 

 

Error respone :-

{"errors":[{"title":"Error extracting message data [missing file object].","detail":"Error extracting message data [missing file object].","code":"ERROR_INTEGRATION-MANAGER_DECODE_ERROR"}]}

 

Screenshot 2019-12-01 at 3.04.51 PM.png

 

Anyone knows how to use InvokeHTTP for multipart?

 

Thanks

Mahendra

 

 

 

 

Don't have an account?
Coming from Hortonworks? Activate your account here