<?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: Nifi Unzip files in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377119#M243136</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105558"&gt;@joseomjr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't found the code that unzip the content of flowfile and send the unzipped files multiple flowfiles&lt;/P&gt;</description>
    <pubDate>Mon, 02 Oct 2023 09:11:10 GMT</pubDate>
    <dc:creator>lafi_oussama</dc:creator>
    <dc:date>2023-10-02T09:11:10Z</dc:date>
    <item>
      <title>Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376837#M243028</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help&lt;/P&gt;&lt;P&gt;I want to unzip file.zip with NiFi&lt;/P&gt;&lt;P&gt;I have used unpackContent processor but that didn't work because of my nifi version 1.13&lt;/P&gt;&lt;P&gt;I have also used executeStreamCommand to execute python script but I didn't found until now the solution&lt;/P&gt;&lt;P&gt;Can you help me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 09:55:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376837#M243028</guid>
      <dc:creator>lafi_oussama</dc:creator>
      <dc:date>2023-09-26T09:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376846#M243031</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/70529"&gt;@lafi_oussama&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;First of all, &lt;STRONG&gt;what is the compression format&lt;/STRONG&gt; of the files you are trying to unzip?&lt;BR /&gt;What error did you receive when using &lt;STRONG&gt;UnpackContent&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;Have you tried using &lt;STRONG&gt;CompressContent&lt;/STRONG&gt; ( &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.CompressContent/" target="_blank"&gt;https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.CompressContent/&lt;/A&gt; )&lt;BR /&gt;You can configure the processed to either &lt;STRONG&gt;compress&lt;/STRONG&gt; or &lt;STRONG&gt;decompress&lt;/STRONG&gt; your files. You have &lt;STRONG&gt;multiple compression formats&lt;/STRONG&gt; from which you can choose from.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:04:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376846#M243031</guid>
      <dc:creator>cotopaul</dc:creator>
      <dc:date>2023-09-26T13:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376852#M243033</link>
      <description>&lt;P&gt;@&lt;A class="lia-link-navigation lia-page-link user-name-link" href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/103151" target="_blank"&gt;&lt;SPAN class=""&gt;cotopaul&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The compression format is .zip.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The CompressContent doesn't work with zip format&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:35:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376852#M243033</guid>
      <dc:creator>lafi_oussama</dc:creator>
      <dc:date>2023-09-26T13:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376867#M243036</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/70529"&gt;@lafi_oussama&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Have you tried upgrading to the latest version of Apache NiFi?&lt;BR /&gt;You have not shared the specific ERROR you are encountering with the UnpackContent processor.&lt;BR /&gt;You have not shared specific around what you tried using the ExecuteStreamCommand and Python scripts.&amp;nbsp;&lt;BR /&gt;Any additional details you can provide about your zip files?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Matt&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:19:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376867#M243036</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2023-09-26T14:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376868#M243037</link>
      <description>&lt;P&gt;I can't upgrade the version of NiFi.&lt;/P&gt;&lt;P&gt;the error I encountered with UnpackContent :&amp;nbsp;Unable to unpack StandardFlowFileRecord[uuid=e94fb414-7fb3-441a-8294-89e2766633a4,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1695735090062-1030, container=default, section=6], offset=0, length=6002134],offset=0,name=outBI.zip,size=6002134] because it does not appear to have any entries; routing to failure&lt;/P&gt;&lt;P&gt;&amp;nbsp;Example of python script that I have executed with ExecuteStreamCommand :&lt;/P&gt;&lt;P&gt;import zipfile&lt;BR /&gt;import sys&lt;BR /&gt;import gzip&lt;BR /&gt;import os&lt;BR /&gt;import io&lt;/P&gt;&lt;P&gt;zip_folder= sys.stdin.buffer.read()&lt;/P&gt;&lt;P&gt;with zipfile.ZipFile(io.BytesIO(zip_folder), 'r') as zip_folder:&lt;BR /&gt;for file_info in zip_folder.infolist():&lt;BR /&gt;file_name = file_info.filename&lt;BR /&gt;# Read the content of the file&lt;BR /&gt;file_content = zip_folder.read(file_name)&lt;BR /&gt;# Print the content to stdout (standard output)&lt;BR /&gt;sys.stdout.buffer.write(file_content)&lt;BR /&gt;sys.stdout.buffer.write(b'\n')&lt;BR /&gt;sys.stdout.flush()&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:31:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376868#M243037</guid>
      <dc:creator>lafi_oussama</dc:creator>
      <dc:date>2023-09-26T14:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376939#M243072</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/70529"&gt;@lafi_oussama&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Does the zipfile actually contain files or only empty directories?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 13:29:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/376939#M243072</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2023-09-27T13:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377107#M243128</link>
      <description>&lt;P&gt;If you can run this python code under Python without any external modules, you should be able to run it as a scripted processor and have everything happen inside of NiFi.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 20:29:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377107#M243128</guid>
      <dc:creator>joseomjr</dc:creator>
      <dc:date>2023-10-01T20:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377118#M243135</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes the zipfile contains mutltiple floders that contain files&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:11:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377118#M243135</guid>
      <dc:creator>lafi_oussama</dc:creator>
      <dc:date>2023-10-02T09:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377119#M243136</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105558"&gt;@joseomjr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't found the code that unzip the content of flowfile and send the unzipped files multiple flowfiles&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:11:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377119#M243136</guid>
      <dc:creator>lafi_oussama</dc:creator>
      <dc:date>2023-10-02T09:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377333#M243228</link>
      <description>&lt;P&gt;Created this Python ExecuteScript NiFi processor that extracts the files of a ZipFile (including those in subdirectories) into individual FlowFiles. It all happens inside of NiFi and not fully tested but it worked with a simple example in my lab.&lt;BR /&gt;&lt;BR /&gt;"Script Body" below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;''' Extract Zip Files '''
from org.apache.commons.io import IOUtils
from org.apache.nifi.processor.io import InputStreamCallback, OutputStreamCallback
import zipfile
from io import BytesIO

class PyInputStreamCallback(InputStreamCallback):
    ''' InputStream Callback '''
    def __init__(self):
        self.zip_file = None

    def process(self, input_stream):
        ''' Process our InputStream '''
        zip_buffer = BytesIO(IOUtils.toByteArray(input_stream))
        self.zip_file = zipfile.ZipFile(zip_buffer, "r")
class PyOutputStreamCallback(OutputStreamCallback):
    ''' OutputStream Callback '''
    def __init__(self, file):
        self.file = file

    def process(self, output_stream):
        ''' Process our OutputStream '''
        output_stream.write(self.file.read())

flow_file = session.get()
if flow_file:
    input_stream_callback = PyInputStreamCallback()
    output_stream_callback = PyOutputStreamCallback
    session.read(flow_file, input_stream_callback)
    zip_filename = flow_file.getAttribute("filename")
    zip_file = input_stream_callback.zip_file
    for name in (name for name in zip_file.namelist() if not name.endswith("/")):
        new_flow_file = session.create()
        new_flow_file = session.putAttribute(new_flow_file, "filename", name)
        new_flow_file = session.putAttribute(new_flow_file, "zip_filename", zip_filename)
        new_flow_file = session.write(
                                        new_flow_file,
                                        output_stream_callback(zip_file.open(name))
                                    )
        session.transfer(new_flow_file, REL_SUCCESS)
    zip_file.close()
    session.remove(flow_file)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 04:49:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/377333#M243228</guid>
      <dc:creator>joseomjr</dc:creator>
      <dc:date>2023-10-08T04:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi Unzip files</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/407130#M252615</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105558"&gt;@joseomjr&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;your code could not work at my end.&amp;nbsp;&lt;BR /&gt;ChatGPT help me with below code and it is working at my end.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import java.util.zip.ZipInputStream
import java.util.zip.ZipEntry
import java.io.ByteArrayOutputStream

def flowFile = session.get()
if (!flowFile) return

try {
    session.read(flowFile, { inputStream -&amp;gt;
        ZipInputStream zipIn = new ZipInputStream(inputStream)
        ZipEntry entry = zipIn.nextEntry

        while (entry != null) {
            if (!entry.isDirectory()) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream()
                byte[] buffer = new byte[8192]
                int len
                while ((len = zipIn.read(buffer)) &amp;gt; 0) {
                    baos.write(buffer, 0, len)
                }

                def contentBytes = baos.toByteArray()
                def newFlowFile = session.create(flowFile)
                newFlowFile = session.write(newFlowFile, { outStream -&amp;gt;
                    outStream.write(contentBytes)
                } as OutputStreamCallback)

                newFlowFile = session.putAttribute(newFlowFile, 'filename', entry.getName())
                session.transfer(newFlowFile, REL_SUCCESS)
            }
            zipIn.closeEntry()
            entry = zipIn.nextEntry
        }

    } as InputStreamCallback)

    session.remove(flowFile)

} catch (Exception e) {
    log.error("Failed to unzip FlowFile due to: ${e.message}", e)
    session.transfer(flowFile, REL_FAILURE)
}&lt;/LI-CODE&gt;&lt;P&gt;I hope there is no security concern with this code!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 05:40:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Unzip-files/m-p/407130#M252615</guid>
      <dc:creator>Shrink</dc:creator>
      <dc:date>2025-04-29T05:40:32Z</dc:date>
    </item>
  </channel>
</rss>

