<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Reading file from folder and creating new flowfile giving error in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348235#M235342</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/95503"&gt;@steven-matison&lt;/a&gt;&amp;nbsp;its is working now..&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;import java.nio.charset.StandardCharsets&lt;BR /&gt;import org.apache.commons.io.IOUtils&lt;BR /&gt;import java.nio.charset.*&lt;BR /&gt;import groovy.io.FileType&lt;BR /&gt;import java.io.*&lt;/P&gt;&lt;P&gt;def flowFile = session.get()&lt;BR /&gt;if(!flowFile) return&lt;BR /&gt;def flowFiles = [] as List&amp;lt;FlowFile&amp;gt;&lt;BR /&gt;def list = []&lt;BR /&gt;def dir = new File("/zyme_shared/nas_data/poc/zgw/output1/")&lt;BR /&gt;dir.eachFileRecurse (FileType.FILES) { file -&amp;gt;&lt;BR /&gt;list &amp;lt;&amp;lt; file&lt;BR /&gt;}&lt;BR /&gt;list.each{ i -&amp;gt;&lt;BR /&gt;def flowFile2 = session.create(flowFile)&lt;BR /&gt;flowFile2 = session.putAttribute(flowFile2, "filename" , i.name)&lt;BR /&gt;flowFile2 = session.write(flowFile2, { outputStream -&amp;gt;&lt;BR /&gt;outputStream.write(i.getBytes())&lt;BR /&gt;} as OutputStreamCallback)&lt;BR /&gt;flowFiles &amp;lt;&amp;lt; flowFile2&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;session.transfer(flowFiles, REL_SUCCESS)&lt;BR /&gt;session.remove(flowFile)&lt;BR /&gt;session.commit()&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2022 15:34:34 GMT</pubDate>
    <dc:creator>rangareddyy</dc:creator>
    <dc:date>2022-07-20T15:34:34Z</dc:date>
    <item>
      <title>Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348228#M235339</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting error in executing below script thru Execute Script processor.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;--------------------------------&lt;BR /&gt;import java.nio.charset.StandardCharsets&lt;BR /&gt;def flowFile = session.get()&lt;BR /&gt;if(!flowFile) return&lt;BR /&gt;def flowFiles = [] as List&amp;lt;FlowFile&amp;gt;&lt;BR /&gt;def inputStream = session.read(flowFile)&lt;BR /&gt;def list = []&lt;BR /&gt;def dir = new File("/root/file_data/poc/output/")&lt;BR /&gt;dir.eachFileRecurse (FileType.FILES) { file -&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;list &amp;lt;&amp;lt; file&lt;BR /&gt;}&lt;BR /&gt;list.each{ i -&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def newFlowFile = session.create(flowFile)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newFlowFile = session.write(newFlowFile, { outputStream -&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;outputStream.write( i.getBytes(StandardCharsets.UTF_8))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} as OutputStreamCallback)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; flowFiles &amp;lt;&amp;lt; newFlowFile&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;session. Transfer(flowFiles, REL_SUCCESS)&lt;BR /&gt;session.remove(flowFile)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 13:50:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348228#M235339</guid>
      <dc:creator>rangareddyy</dc:creator>
      <dc:date>2022-07-20T13:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348232#M235341</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/56607"&gt;@rangareddyy&lt;/a&gt;&amp;nbsp; &amp;nbsp;I recently did something similar, and each time, in the code, that i wanted to send flowfile i used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;session.transfer(flowFile2, REL_SUCCESS)&lt;BR /&gt;session.commit()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;It is my understanding in a single flowfile example, the commit() is inferred upon script completion.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 14:27:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348232#M235341</guid>
      <dc:creator>steven-matison</dc:creator>
      <dc:date>2022-07-20T14:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348235#M235342</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/95503"&gt;@steven-matison&lt;/a&gt;&amp;nbsp;its is working now..&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;import java.nio.charset.StandardCharsets&lt;BR /&gt;import org.apache.commons.io.IOUtils&lt;BR /&gt;import java.nio.charset.*&lt;BR /&gt;import groovy.io.FileType&lt;BR /&gt;import java.io.*&lt;/P&gt;&lt;P&gt;def flowFile = session.get()&lt;BR /&gt;if(!flowFile) return&lt;BR /&gt;def flowFiles = [] as List&amp;lt;FlowFile&amp;gt;&lt;BR /&gt;def list = []&lt;BR /&gt;def dir = new File("/zyme_shared/nas_data/poc/zgw/output1/")&lt;BR /&gt;dir.eachFileRecurse (FileType.FILES) { file -&amp;gt;&lt;BR /&gt;list &amp;lt;&amp;lt; file&lt;BR /&gt;}&lt;BR /&gt;list.each{ i -&amp;gt;&lt;BR /&gt;def flowFile2 = session.create(flowFile)&lt;BR /&gt;flowFile2 = session.putAttribute(flowFile2, "filename" , i.name)&lt;BR /&gt;flowFile2 = session.write(flowFile2, { outputStream -&amp;gt;&lt;BR /&gt;outputStream.write(i.getBytes())&lt;BR /&gt;} as OutputStreamCallback)&lt;BR /&gt;flowFiles &amp;lt;&amp;lt; flowFile2&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;session.transfer(flowFiles, REL_SUCCESS)&lt;BR /&gt;session.remove(flowFile)&lt;BR /&gt;session.commit()&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 15:34:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348235#M235342</guid>
      <dc:creator>rangareddyy</dc:creator>
      <dc:date>2022-07-20T15:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348238#M235343</link>
      <description>&lt;P&gt;This is a groovy error.&amp;nbsp; I would suggest having a working groovy script executeable outside of nifi before trying to modify and execute that code in the context of ExecuteScript.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 15:09:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348238#M235343</guid>
      <dc:creator>steven-matison</dc:creator>
      <dc:date>2022-07-20T15:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348247#M235346</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/56607"&gt;@rangareddyy&lt;/a&gt;&amp;nbsp;You will need to add attributes to the flowfile:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;flowFile = session.putAttribute(flowFile, 'myAttr', 'myValue')&lt;/PRE&gt;&lt;P&gt;Reference:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;A href="https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922" target="_blank"&gt;https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 15:22:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348247#M235346</guid>
      <dc:creator>steven-matison</dc:creator>
      <dc:date>2022-07-20T15:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading file from folder and creating new flowfile giving error</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348251#M235347</link>
      <description>&lt;P&gt;I think you will also need to do the transfer/commit in the each list logic&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 15:23:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Reading-file-from-folder-and-creating-new-flowfile-giving/m-p/348251#M235347</guid>
      <dc:creator>steven-matison</dc:creator>
      <dc:date>2022-07-20T15:23:23Z</dc:date>
    </item>
  </channel>
</rss>

