Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

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

avatar
Expert Contributor

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
Master Collaborator

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.