Reputation: 41
I am trying to send a multipart/form-data
request to a POST API using Nifi's InvokeHTTP
processor. This request takes a JSON and a file. The request headers and request body in Postman look something like this:
POST /delivery/deliverPackage
User-Agent: PostmanRuntime/7.6.1
Accept: */*
Host: example.hostname:port
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------161413078116998145311888
content-length: 1115
json={ "destinationProtocol" : "HL7", "destinationFormat": "HL7_V2_ORU", "destinationType": "example", "destinationConnectionParams":{ "URI": "example", "HOST": "example", "PORT": "example" } }file=[object Object]
where the file object contains the file details I am trying to send.
I want to send this multipart/form-data
request in Nifi. Based on an answer I saw on one of the forums, I am trying to create this request body in the content of the FlowFile using the ReplaceText
processor before sending the FlowFile to an InvokeHttp
processor. The FlowFile content looks something like this:
POST /delivery/deliverPackage
User-Agent: curl/7.46.0
Accept: */*
Host: example.hostname:port
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------161413078116998145311888
content-length: 1115
--------------------------161413078116998145311888
Content-Disposition: form-data; json="{ "destinationProtocol" : "HL7", "destinationFormat": "HL7_V2_ORU", "destinationType": "example", "destinationConnectionParams":{ "URI": "example", "HOST": "example", "PORT": "example" } }"
anonymous
--------------------------161413078116998145311888
Content-Disposition: form-data; name="file"; filename="/path/to/file/in/localsystem.HL7”
Content-Type: text/plain
contents of the file
--------------------------161413078116998145311888--
This doesn't seem to be working though, it doesn't look right. I am pretty new to Nifi. Can anyone help me understand what I'm doing wrong or give some insights on handling this properly?
EDIT
I have instead tried to use an ExecuteStreamCommand
processor to simply run the curl command with command arguments -
-X POST;"https://example.hostname:port/delivery/deliverPackage?json=%7B%20%22destinationProtocol%22%20%3A%20%22HL7%22%2C%20%22destinationFormat%22%3A%20%22HL7_V2_ORU%22%2C%20%22destinationType%22%3A%20%22example%22%2C%20%22destinationConnectionParams%22%3A%7B%20%22URI%22%3A%20%22example%3A%2F%2Fexample%3A15050%22%2C%20%22HOST%22%3A%20%22example%22%2C%20%22PORT%22%3A%20%22example%22%20%7D%20%7D";-H "Content-Type: multipart/form-data";-F "file=@/path/to/file/in/localsystem.HL7";
This works, but I wanted to know how to do it using the InvokeHttp
processor. Any help is greatly appreciated!
Upvotes: 4
Views: 2410
Reputation: 5271
You can do this by using: GenerateFlowFile -> InvokeHTTP.
The GenerateFlowFile would create the payload (in your case the content of localsystem.HL7
) of your post in the Custom Text field.
The InvokeHTTP will need to have Content-Type
as ${mime.type}
- default value and then see what the output is after your POST
Upvotes: 0