Support Questions

Find answers, ask questions, and share your expertise

Hosting API using HandleHttpRequest

avatar
Contributor

Hi 

How do I host an API using HandleHttpRequest which can be used to upload files to NiFi server from local using "multipart/form-data".

Have tried below approach, however I get read permission issue as the Nifi user can't access local data.

Screenshot 2024-11-01 at 10.11.06 PM.png

Please suggest an approach which can be used to upload file from local.

Thanks

 

5 REPLIES 5

avatar
Master Mentor

@nifier 

I am not very clear on yoru use case.

From your dataflow it appears some external source is making a rest-api call to the endpoint created by the HandleHTTPRequest processor.  The FlowFile produced by the HandleHTTPRequest processor contains necessary information to identify which file needs to be fetched from the local NiFi host's filesystem. 

What other info are you exposing through your rest-api request to the HandleHTTPRequest processor?  

The FetchFile processor is the one producing the read permission exception, correct?

All components added to the NiFi canvas execute as the NiFi service user.  This means the NiFi service user needs to be authorized to read on the local files in order to ingest them.

The local filesystem NiFi processor components do not provide an option to execute as another user.  

Also your use case feels a bit dangerous from a security standpoint.  You are exposing a rest-api endpoint multiple user could potentially reach to fetch files.  I see no protection build into your dataflow.

Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.

Thank you,
Matt

avatar
Contributor

@MattWho 

Thanks for you response.

Use case is basically to only upload file using API, and not to download.

 We have an UI which is used upload a file, On click of choose file we were planning to call our backend API which inturn calls NiFi HandleHTTPRequest API. 

Authorization will part of UI and API.

Also, NiFi API will not be directly exposed externally. 

Screenshot 2024-11-02 at 8.54.13 AM.png

 

Since we were exploring our options in Nifi, we are trying this approach.

If you feel this is not achievable or not the right approach, we can drop this and look into other options.

Thank you

avatar
Super Collaborator

I've done something similar where I use a custom Groovy processor to handle the file uploaded and posted to the HandleHTTPRequest does something with the data and provides a JSON response to HandleHTTPResponse

joseomjr_0-1730591947548.png

 

avatar
Contributor

@joseomjr 

Thanks for the reply.

So you are reading the file from local using Groovy processor which is invoked  in InvokeScriptedProcessor ??

avatar
Super Collaborator

The Groovy processor takes the incoming FlowFile and does stuff with it and writes a new FlowFile with the repsonse. What I tried was a JSON upload but will try "multipart/form-data" if I get a chance and see how that looks.