Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NiFi Question: How to reference flow file in processor

Solved Go to solution
Highlighted

NiFi Question: How to reference flow file in processor

Super Collaborator

(I'm still getting familiar w/ NiFi, so this might have a really obvious answer)

I have a flow where I take a text file that contains a per-line list of files. I grab this file with a FetchFile processor, and then feed the output to a SplitText processor, giving me one flow file per row.

So my flow file is literally just a string with a file path "x", like '/home/zack/my_folder/my_file'.

Then, I want to add either a FetchFile processor or a ExecuteStream processor to get the file represented by "x" and copy it to a different folder.

However, I can't figure out how to reference "x".

Is there a way, using the markup language I would guess, to somehow get a handle on that file path string so I can use it?

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: NiFi Question: How to reference flow file in processor

@Zack Riesland

You would have to use ExtractText processor to extract the path and set it as an attribute of your flow file. Then you can use this attribute using expression language in the next processors.

Let's say you extract .* to put it as attribute "mypath", then in following processor, for properties accepting expression language, you can reference this value using ${mypath}.

Hope this helps.

View solution in original post

3 REPLIES 3

Re: NiFi Question: How to reference flow file in processor

@Zack Riesland

You would have to use ExtractText processor to extract the path and set it as an attribute of your flow file. Then you can use this attribute using expression language in the next processors.

Let's say you extract .* to put it as attribute "mypath", then in following processor, for properties accepting expression language, you can reference this value using ${mypath}.

Hope this helps.

View solution in original post

Highlighted

Re: NiFi Question: How to reference flow file in processor

Super Collaborator

Thanks Pierre,

A quick followup question:

How can I use the markup language to strip the path from a file?

So, in the example above, how do I get 'my_file' from 'home/zack/my_folder/my_file' ?

I'm guessing I use a UpdateAttribute processor... thanks!

Highlighted

Re: NiFi Question: How to reference flow file in processor

Yes correct. You could also do both in once with ExtractText processor, but you definitely can use UpdateAttribute and expression language functions to get the result you want. Also if you only need the filename for a processor in a property accepting expression language, you don't need the intermediate step. For example:

${mypath:substringAfterLast('/')}

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

Hope this helps.

Don't have an account?
Coming from Hortonworks? Activate your account here