title: How to send an http POST multipart/form-data request with a file attached using Apache-nifi's InvokeHttp processor?
body: <p>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 - </p>
  
  <pre><code>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]
  </code></pre>
  
  <p>where the file object contains the file details I am trying to send.</p>
  
  <p>I want to send this multipart/form-data request in nifi. Based on an answer I saw on one of the forums (sorry do not have the link to it), I am trying to create this request body in the content of the flowfile using ReplaceText processor before sending the flowfile to an InvokeHttp processor. The flowfile content looks something like this - </p>
  
  <pre><code>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--
  </code></pre>
  
  <p>This doesn't seem to be working though, it doesn't look right to me. I am pretty new to Nifi. Can anyone help me understand what I'm doing wrong or give some insights on how to handle this properly? Thanks!</p>
  
  <p>I have instead tried to use an ExecuteStreamCommand processor to simply run the curl command with command arguments -</p>
  
  <pre><code>-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";
  </code></pre>
  
  <p>This works, but I wanted to know how to do it using the InvokeHttp processor. Any help is greatly appreciated! Thank you.</p>