Skip to main content
SushmaNaya
Silver ⭐️
July 23, 2024
Solved

NiFi : invokehttp processor - multipart/form-data

Hello, I m sending a http request to an API and facing some difficulties to configure the multipart specificities.

I have to send 2 files as part of request. Is there any way to send 2 files ? Since there can be only one flow file that is possible 

 


@SAMSAL
This works fine when one file is being sent. Any help on sending 2 of them ?

 

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
July 23, 2024

Hi @SushmaNaya ,

I believe this was asked before here but I dont think there is  a way to do it in one shot. you probably have to do it in custom script like executeScript processor where you can have part of the data stored as an attributes (depending how big the part is ) and then the other part is your flowfile content or have both stored as attributes (not recommended). Once you get the flowfile the execute script will get the content of the flowfile and the other aprt form the attribute construct your multi part body and send it that way. By the way if you are using Nifi 2.0 you probably can utilize python extensions to create your own custom processor using pure python when you can use different packages to help you with that. You can find example here: https://community.cloudera.com/t5/Support-Questions/Nifi-1-18-multipart-form-data-with-binary-part-and-json-part/m-p/386351#M246014

https://www.w3schools.com/python/ref_requests_post.asp

Hope that helps

2 replies

SushmaNaya
Silver ⭐️
July 23, 2024

SushmaNaya_0-1721708871914.png

 

Translate
SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
July 23, 2024

Hi @SushmaNaya ,

I believe this was asked before here but I dont think there is  a way to do it in one shot. you probably have to do it in custom script like executeScript processor where you can have part of the data stored as an attributes (depending how big the part is ) and then the other part is your flowfile content or have both stored as attributes (not recommended). Once you get the flowfile the execute script will get the content of the flowfile and the other aprt form the attribute construct your multi part body and send it that way. By the way if you are using Nifi 2.0 you probably can utilize python extensions to create your own custom processor using pure python when you can use different packages to help you with that. You can find example here: https://community.cloudera.com/t5/Support-Questions/Nifi-1-18-multipart-form-data-with-binary-part-and-json-part/m-p/386351#M246014

https://www.w3schools.com/python/ref_requests_post.asp

Hope that helps

Translate