Frank Leverenz
Frank Leverenz

Reputation: 309

NiFi InvokeHttp: How to send multiple files with multipart/form-data without ExecuteGroovyScript

Normally, when I have to POST multiple files with multipart/form-data to a RestAPI-Server, I use ExecuteGroovyScript as described here:

http://apache-nifi-users-list.2361937.n4.nabble.com/POST-multipart-form-data-with-Invokehttp-td9374.html

Now, my NiFi flow should run on a different server and I get:

'GroovyScript' is invalid because ... unresolved dependency: org.apache.httpcomponents#httpmime

I have no admin access to this NiFi-Server and I can't change the NiFi configuration so I can't fix the GroovyScript error.

Is it possible to send multiple files with multipart/form-data only with the InvokeHttp processor?

(I didn't find any working solution with Google)

Upvotes: 2

Views: 815

Answers (1)

soith
soith

Reputation: 96

If you have the NiFi policy access to restricted components (requiring 'execute code'), there is a way to get the Groovy script processor working without admin-access to this NiFi-Server (presuming you are referring to the operating system level access).

Fortunately, the JARs needed by the Groovy script you reference are bundled with NiFi and flows have access to them by necessity. You should be able to get the processor to work by setting the Additional classpath property of the ExecuteGroovyScript processor to something like: ${nifi.nar.working.directory}/framework/nifi-framework-nar-1.11.4.nar-unpacked/NAR-INF/bundled-dependencies/httpcore-4.4.9.jar;${nifi.nar.working.directory}/extensions/nifi-slack-nar-1.11.4.nar-unpacked/NAR-INF/bundled-dependencies/httpmime-4.5.7.jar.

Here, nifi.nar.working.directory is a NiFi variable set to the same value as what it is in the nifi.properties file. NB: You will need to change the version information in this example if you are not using NiFi 1.11.4.

Explanation: the NiFi framework includes the class org.apache.http.entity.ContentType. Several NiFi extensions include the class org.apache.http.entity.mime.MultipartEntityBuilder: media (has the most recent JAR version, but is not currently bundled with the NiFi distribution); slack (has the next most recent JAR version); and solr.

Caveat: This approach is fragile because it will break during a NiFi upgrade. A way to guard against this is to have a NiFi flow that gets the two JAR files and puts them to a location that will be preserved during an upgrade. Then the Additional classpath property of the ExecuteGroovyScript processor would refer to this preserved location. (You would need the NiFi policy, access to restricted components (requiring 'write filesystem') to create this flow.)

Upvotes: 1

Related Questions