Skip to main content
piyush7829
Silver ⭐️⭐️
February 29, 2024
Solved

How to send the POST multipart/form-data using InvokeHTTP processor 1.20.0

Hello,

I am getting the data from GetMongo Processor then i am evaluating the JSON Path using EvaluateJSONPath where i am getting series_id and then I am doing in InvokeHTTP.  I am able to send as json but i am not able to send as form-data. Can you please suggest me what i am doing wrong here.

piyush7829_0-1709244479997.pngpiyush7829_1-1709244502313.png

Before invokeHTTP the data flow is 

piyush7829_4-1709244594014.png

 

 

piyush7829_2-1709244523350.pngpiyush7829_3-1709244544565.png

 

 

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
March 1, 2024

hi @piyush7829 ,

Can you provide more info on what the issue is? Are you getting error messages in the failure , retry relationships? Are you not getting any response at all? Are you sure that your api takes the data as request body and not as post form data key value as the processor description indicates :

SAMSAL_1-1709261465067.png

Also I dont see that you are setting the Request Content-Type property to: multipart/form-data

Here are some posts that might help get it working:

https://community.cloudera.com/t5/Support-Questions/How-to-send-an-http-POST-multipart-form-data-request-with-a/m-p/240035

 

https://palindromicity.blogspot.com/2020/04/sending-multipart-form-data-with.html

 

https://stackoverflow.com/questions/51929208/how-to-send-multipart-form-data-via-invokehttp-nifi

 

If you find this is helpful please accept solution.

Thanks

4 replies

DianaTorres
Community Manager
Community Manager
March 1, 2024

@piyush7829 Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @MattWho @mburgess  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.

Translate
Regards, Diana Torres, Senior Community Moderator
SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
March 1, 2024

hi @piyush7829 ,

Can you provide more info on what the issue is? Are you getting error messages in the failure , retry relationships? Are you not getting any response at all? Are you sure that your api takes the data as request body and not as post form data key value as the processor description indicates :

SAMSAL_1-1709261465067.png

Also I dont see that you are setting the Request Content-Type property to: multipart/form-data

Here are some posts that might help get it working:

https://community.cloudera.com/t5/Support-Questions/How-to-send-an-http-POST-multipart-form-data-request-with-a/m-p/240035

 

https://palindromicity.blogspot.com/2020/04/sending-multipart-form-data-with.html

 

https://stackoverflow.com/questions/51929208/how-to-send-multipart-form-data-via-invokehttp-nifi

 

If you find this is helpful please accept solution.

Thanks

Translate
piyush7829
Silver ⭐️⭐️
March 1, 2024

Hello  @SAMSAL ,

Thanks that do work. But I have one more question related to same .

I have added as you suggested post:form:series_id : 323

But I need to display value dynamically.  as I have shown in the above screenshot I am getting {"series_id" : 323} above InvokeHTTP.  I want to send that series_id which is coming in the data flow in the form. I am not able to achieve that. 

piyush7829_0-1709285530015.png

 

 

 

Translate
SAMSAL
Platinum ⭐️⭐️⭐️
March 1, 2024

Hi @piyush7829 ,

Glad it worked and you were able to do the post. If I understood your question correctly then you need to pass the series_id to the post:form:series_id multipart form property dynamically, right? If that is the case then its easy since the InvokeHttp multipart dynamic properties allows for expression language you can reference the series_id attribute you have extracted using the EvaluateJsonPath and assign it as follows:

post:form:series_id: ${series_id}

Every time the invokeHttp is triggered it would evaluate the series_id expression from the incoming flowfile and assign its value before making the api invokation.

Hope that helps.

 

Translate