Created on 10-04-2022 04:49 PM - edited 10-04-2022 09:14 PM
How can I use the output of the Base64EncodeContent (or the Base64Encode function) as input for an XML template, where the flow file content (not an attribute) is the XML with the encoded value included? There doesn't seem to be a NiFi reader that reads the encoded flow file content, so I'm not sure how best to use this processor aside from using a couple of ReplaceText processors to bracket XML substrings around it.
I appreciate any input. Thanks for reading.
example:
Initial Flow File: "The quick brown fox jumped over the lazy dog"
Encoded Flow File: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2c=
<?xml version="1.0" encoding="UTF-8" ?>
<a xmlns="some/name/space/goes/here">
<b>This is a template</b>
<c>ENCODED DATA GOES HERE</c>
</a>
Created on 10-06-2022 08:33 AM - edited 10-06-2022 08:35 AM
Since ReplaceText can make use of regex groups, I believe you could do something along the lines of
Match text: (.*)
Replace text:<xml> '$1'</xml>
$1 allows you to inject the first regex group you match, which in case of the regex above would match the entire file content. I may be wrong about needing to surround it with single quotes but a quick read of the processor's documentation should clear things up.
This could be a hefty task if you need to load massive files into memory, however I don't believe your encoded strings should pose a problem.
Hope this helps, it's always nice to optimize flows 🙂
Created 10-06-2022 04:20 AM
I believe a ReplaceText where you just match the entire encoded content and then inject it into an xml already written as the replacement value would be the ideal way to do this.
Created on 10-06-2022 08:20 AM - edited 10-06-2022 08:22 AM
Are you suggesting it is possible to perform a complete swap of the flow file content using a ReplaceText processor?
For example:
If the flow file = "ababababac"
Can I use a single ReplaceText to create <xml>ababababac</xml>?
From everything I've read in the docs you can't use the Expression Language to get at the whole of the flow file content, e.g. ${flowFile}
So instead what I do is use 2 ReplaceText processors successively; the first one performs a "Prepend", and the second one performs an "Append". This technique just bookends (brackets) the flow file content.
For example:
Base64Encode ReplaceText (prepend) ReplaceText(append)
ababababac ==> <xml>ababababac ==> <xml>ababababac</xml>
But, if you know of a way to do this with a single processor then I'd love to hear your suggestions.
Thanks!
Created on 10-06-2022 08:33 AM - edited 10-06-2022 08:35 AM
Since ReplaceText can make use of regex groups, I believe you could do something along the lines of
Match text: (.*)
Replace text:<xml> '$1'</xml>
$1 allows you to inject the first regex group you match, which in case of the regex above would match the entire file content. I may be wrong about needing to surround it with single quotes but a quick read of the processor's documentation should clear things up.
This could be a hefty task if you need to load massive files into memory, however I don't believe your encoded strings should pose a problem.
Hope this helps, it's always nice to optimize flows 🙂
Created 10-06-2022 11:42 AM
Brilliant! That does the trick. Thanks!