Created 11-01-2024 09:43 AM
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.
Please suggest an approach which can be used to upload file from local.
Thanks
Created 11-01-2024 01:36 PM
@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
Created on 11-01-2024 08:23 PM - edited 11-02-2024 01:48 AM
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.
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
Created 11-02-2024 04:59 PM
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
Created 11-04-2024 12:21 AM
Thanks for the reply.
So you are reading the file from local using Groovy processor which is invoked in InvokeScriptedProcessor ??
Created on 11-04-2024 06:51 PM - edited 11-04-2024 06:55 PM
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.