Reading file from folder and creating new flowfile giving error
Hi All,
Getting error in executing below script thru Execute Script processor.
Requirement : upper flow will copy files to some folder.. trying to read files from folder and post them to http processor. For each file i am trying to create a new flowfile and move the same to HTTP processor. But below code failing. Can you please suggest what i am missing.
--------------------------------
import java.nio.charset.StandardCharsets
def flowFile = session.get()
if(!flowFile) return
def flowFiles = [] as List<FlowFile>
def inputStream = session.read(flowFile)
def list = []
def dir = new File("/root/file_data/poc/output/")
dir.eachFileRecurse (FileType.FILES) { file ->
list << file
}
list.each{ i ->
def newFlowFile = session.create(flowFile)
newFlowFile = session.write(newFlowFile, { outputStream ->
outputStream.write( i.getBytes(StandardCharsets.UTF_8))
} as OutputStreamCallback)
flowFiles << newFlowFile
}
session. Transfer(flowFiles, REL_SUCCESS)
session.remove(flowFile)
Thanks in advance!

