Support Questions

Find answers, ask questions, and share your expertise

How to handle a json body and file in the same request in NiFi

avatar
Rising Star

Hello I need help how to make a flow which can handle 2 pieces of data from user. Let us consider a scenario-> User submits a form having some fields like name, age, address and also a file having something say a list of his hobbies(just for example). How do we process these together and return a response back?

I have my flow like this HandleHttpRequest->ExecuteScript (Groovy)-> HandleHttpResponse

I am able to do one logic only that either handle the json body say {"name":"Test Name","age":"25","address":"Test address"} or the file which gets sent.
How to process both inside my Groovy Script? 

1 REPLY 1

avatar
Contributor

Hello @AlokKumar

Thanks for using Cloudera Community. 

As I understand, what you need is to add one more step in your flow: 
HandleHttpRequest-> MergeContent -> ExecuteScript (Groovy)-> HandleHttpResponse

Since you have JSON fields and files, you're getting multiple FlowFiles.
So this extra MergeContent phase will combine the JSON and the file into a single FlowFile 

On the MergeContent, set Merge Strategy as “Defragment” and set Correlation Attribute Name as http.request.id. that is unique from each HandleHttpRequest


Regards,
Andrés Fallas
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.