Member since
05-18-2021
1
Post
0
Kudos Received
0
Solutions
05-18-2021
11:47 PM
@hegdemahendra i were able to generate dynamic multipart payload via below groovy script @hegdemahendra wrote: I could not succeed in multipart upload with InvokeHTTP processor. So I used a simple java code to upload file using 'multipart/form-data'. Invoked java code from nifi SprintContextProcessor. As my file was large, I wrote the file content to disc before invoking 'SprintContextProcessor' and using java code read the file content and uploaded to the target. You can transfer flow file content directly to the java code (SpringContext processor). Thanks Mahendra import groovy.json.JsonSlurper
@Grab("org.apache.httpcomponents:httpmime:4.3.6")
import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.entity.mime.content.StringBody
import org.apache.nifi.processor.io.InputStreamCallback
import org.apache.nifi.processor.io.OutputStreamCallback
MultipartEntityBuilder multipartRequestEntity = new MultipartEntityBuilder()
multipartRequestEntity.addPart('id', new StringBody("id"))
multipartRequestEntity.addPart('version', new StringBody("version"))
//
//
def slurper = new JsonSlurper();
resp = multipartRequestEntity.build()
flowFile = session.get()
session.read(flowFile, { inputStream ->
jsonInput = slurper.parse(inputStream);
} as InputStreamCallback)
flowFile = session.write(flowFile, {
outputStream -> resp.writeTo(outputStream);
} as OutputStreamCallback)
flowFile = session.putAttribute(flowFile, "mime.type", resp.getContentType().getValue())
flowFile = session.putAttribute(flowFile, "Content-Type", resp.getContentType().getValue())
session.transfer(flowFile, REL_SUCCESS) https://gist.github.com/cedric05/b3c77809ecf6e566593e3af599edee5f connect this to invokehttp processor. you will be able to make multipart http request. above script should be used incase of dynamic multipart, for static use invokehttp directly with properties `post:form:key`: `<data>`
... View more