Support Questions

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

NiFi - How to Write a Flowfile Attribute to a File

avatar
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

avatar

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

View solution in original post

7 REPLIES 7

avatar

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

avatar

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.

avatar

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?

avatar
New Contributor

how do you get the AttributesAsContent in the PutFile processor?

avatar
New Contributor

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

avatar

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.

avatar

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.