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 - How to Write a Flowfile Attribute to a File

Solved Go to solution
Highlighted

NiFi - How to Write a Flowfile Attribute to a File

New Contributor

I have an XML file which I send to an EvaluateXPath processor. The destination of the EvaluateXPath is flowfile-attribute, and it has one user-defined property with the XPath. I can see that that the attribute has the correct value. Now I would like to write the contents of this attribute to a file on the file system. Does anyone know how to do this?

,

1 ACCEPTED SOLUTION

Accepted Solutions

Re: NiFi - How to Write a Flowfile Attribute to a File

Hi Karri,

The simplest way to do it to convert your attributes to json and then store it. you can use AttributesToJSON processor:

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.AttributesToJS...

Thanks,

Jobin

7 REPLIES 7

Re: NiFi - How to Write a Flowfile Attribute to a File

Hi Karri,

The simplest way to do it to convert your attributes to json and then store it. you can use AttributesToJSON processor:

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.AttributesToJS...

Thanks,

Jobin

Re: NiFi - How to Write a Flowfile Attribute to a File

I don't agree with this answer. All AttributesToJSON would do is wrap the attribute in a JSON object and either put it to another attribute or replace the content. If the user is OK with replacing the content then EvaluateXPath with a destination of "flowfile-content" would be the best. Also it ignores the core question, how to put the value generated by EvaluateXPath to disk.

Re: NiFi - How to Write a Flowfile Attribute to a File

Agreed. But Does EvaluateXPath --> save to flowFile Content give you an option at all to deal with original incoming file? Something like below would do both i guess.

EvaluateXpath(Set to Attributes) [match]--> PutFile/DoSomethingElse

EvaluateXpath(Set to Attributes) [match]--> AttributesToJSON-->PutFIle(AttributesAsContent)

10933-screen-shot-2016-12-29-at-115209-am.png

Any suggestion/better way to make it better?

Re: NiFi - How to Write a Flowfile Attribute to a File

New Contributor

how do you get the AttributesAsContent in the PutFile processor?

Re: NiFi - How to Write a Flowfile Attribute to a File

New Contributor

Thanks. I got this to work using the AttributesToJSON processor.

Re: NiFi - How to Write a Flowfile Attribute to a File

It would be much easier if you could set the Destination of EvaluateXPath to "flowfile-content". Are you able to do that? If so, do that and then you can do "PutFile" to write the content of the FlowFile to the FileSystem.

Re: NiFi - How to Write a Flowfile Attribute to a File

New Contributor

You can use replacetext processor and in place of replacement use the attribute name you want to have in your flow file.

One thing you must keep in mind that attributes are stored in memory.