I'm trying to load the contents of a file into an attribute and preface it with "Bearer ". This is how far I got:
def flowFile = session.get();
if (flowFile != null) {
def token = flowFile.getAttribute("token")
def message = "Bearer " + token
flowFile = session.putAttribute(flowFile, "message", message)
session.transfer(flowFile, REL_SUCCESS)
}
However I'm stuck trying to load file contents rather than using .getattribute. Can anyone please help me?
EDIT: To confirm, this is to load the contents of a txt file.
you could use ExecuteGroovyScript with following code to read flowfile content and put it into an attribute:
def ff = session.get()
if(!ff)return
ff.message = "Bearer " + ff.read().getText("UTF-8")
REL_SUCCESS << ff
to read usual file just replace ff.read().getText("UTF-8")
with new File("path/to/file.txt").getText("UTF-8")
NOTE: beware to store large values into attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With