Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi 1.18 multipart/form-data with binary 'part' and json'part'

avatar
Explorer

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

The 1st part should be binary (gzip) and named (data) and the second part should be json file and named (parameters). this works corretly with post man

bou7miiiz_0-1709648920450.png

but I m not able to do the same thing with Nifi 1.18

this is my workflow

bou7miiiz_1-1709648950560.png

 

bou7miiiz_2-1709648965425.png

 

bou7miiiz_3-1709648988391.png

 

bou7miiiz_4-1709649008588.png

if someone faced this situation, plz share your feedbacks

 

 

8 REPLIES 8

avatar
Community Manager

@bou7miiiz Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @mburgess @MattWho  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.


Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar

Hi @bou7miiiz ,

Its hard to tell what is wrong from what you provided because you seem to everything setup accordingly but Im not familiar with what type of API you are working with so its hard to tell. First, I would like to know what is happening when you run the InvokeHttp? are you getting an error? what type of error and response code are you getting?

Second, I noticed in Postman you are referencing the json parameters value form a file, did you try to pass the json itself instead because that is what you are doing with Nifi.

 

avatar
Explorer

thank you for your answer Samsal,

its a rest API via HTTP

the invokHttp is not throwing any error

bou7miiiz_0-1709715787282.png

and m getting a 415 error with an empty response 

bou7miiiz_1-1709716079282.png

bou7miiiz_2-1709716301383.png

and yes when I try to change the file in postman with a text, I get the same error

bou7miiiz_3-1709716410998.png

< 415 Unsupported Media Type
< accept: application/json, application/cbor, application/xml;charset=UTF-8, application/*+json, text/xml;charset=UTF-8, application/*+xml;charset=UTF-8
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< content-length: 0
< content-security-policy: frame-ancestors https://sgconnect-hom.fr.world.socgen 'self'
< date: Wed, 06 Mar 2024 09:23:07 GMT
< expires: 0
< pragma: no-cache
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-content-type-options: nosniff
< x-frame-options: DENY
< x-xss-protection: 1; mode=block

 

 

however, when specifying the content type for the parameters it's working (in postman)

bou7miiiz_4-1709717187185.png

the probleme is that I m not able to specify the second content type "application/json" and it's mandatory either with file or text

avatar

This is interesting. I never came across a case where you need to specify the content-type on the form data itself & I cant find anything for that in the invokehttp documentation.  @MattWho , @cotopaul , @joseomjr  do you have any information on this?

 

When I look into how the type is passed using curl for example, it looks like the following:

--form 'Parameters="...";type=application/json' 

I'm not sure this is going to work but when you set the post:form:parameters value try to append the type to the json string as follows:

${JSONAttributes:append(";type=application/json")}

If that doesnt help. Im not sure how can you do such thing without using something like ExecuteScript processor and write code like groovy to execute the API call.

I apologize if I did not have straight answer.

 

avatar
Explorer

unfortunatly it's not working, however if this can help, in Nifi 1.11 i m using a groovy script (I thought that I can avoid it by migrating to 1.18)

bou7miiiz_0-1709730974454.png

 

avatar

@bou7miiiz are you setting the mime type in the post HEADERS from nifi to the api?

The 415 error seems to be expecting "application/json".

 

Add this property the same way you added Authorization.

avatar
Explorer

how can I add this property to the invokHttp? I should precise that this content-type is only for the json part. the other part should be application/octet-stream

avatar
Super Collaborator

What headers do you set inside of Postman?