nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy LoPresto <>
Subject Re: Reading flowfile in a stream callback
Date Fri, 03 Nov 2017 00:26:35 GMT

The Python API should be the same as the Java interface [1]. Matt Burgess’
blog has a good post about using Jython to do flowfile content manipulation. Something like:

flowFile = session.get()
if (flowFile != None):
  flowFile = session.write(flowFile,PyStreamCallback())
  session.transfer(flowFile, REL_SUCCESS)

With PyStreamCallback declared as a class above that block in the script:

from import IOUtils
from java.nio.charset import StandardCharsets
from import StreamCallback

class PyStreamCallback(StreamCallback):
  def __init__(self):
  def process(self, inputStream, outputStream):
    text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
    reversedText = text[::-1]


In Groovy, you can declare the StreamCallback as an inline closure to make this more compact,
but I believe in Jython it needs to be a separate declaration. Hope this helps.

[2] <>

Andy LoPresto
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Nov 2, 2017, at 12:53 PM, James McMahon <> wrote:
> In python, I can use the requests library to post content something like htis:
> import requests
> url=" <>"
> files={'file':open('/somedir/myfile.txt','rb')}
> r =,files=files)
> If I am in a python stream callback, how can I read the flowfile payload in the same
way that the open() reads its file from disk?

View raw message