Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to uncompress a zip file which has a folder in Nifi?

How to uncompress a zip file which has a folder in Nifi?

Suppose we have a zip file which has a folder and within folder it files a.txt.b.txt,c.txt

test.zip -> test_folder-> a.txt,b.txt,c.txt

It seems that that unpack processor does not support this type of extract

4 REPLIES 4

Re: How to uncompress a zip file which has a folder in Nifi?

Super Guru
@vinayak krishnan

by using unpack content processor recursively unpacks all the files from .zip file i.e we are not going to get test_folder.

But Unpack Content processor adds path attribute that will have value that describes what is the actual path in your case test/test_folder.

If you want to create intermediate folder that will have all the files in it then use

Merge Content processor with Merge Strategy as FlowFile Stream, v3 and correlation attribute value as path

By using MergeContent processor we are creating .PKG flowfile which will have individual files packaged together based on correlation attribute.

If you want to change the filename then use UpdateAttribute processor after MergeContent processor

filename

${path:substringAfterLast("/")}

for windows

${path:substringAfterLast('${literal("\")}')}

Now we are updating the .PKG name to the actual folder name inside .zip file.

If you want to uncompress/unpack these .PKG flowfile then use

UnpackContent processor with

Packaging Format

use mime.type attribute //as this attribute added by merge content processor

Now you are going to have all the files unpacked from .PKG flowfile.

By using MergeContent processor we can create intermediate .PKG flowfiles then unpack the .PKG when ever you needed in your flow.

Sample Flow:-

72821-flow.png

Reference flow.xml 191223-uncompress.xml

-

If the Answer addressed your question, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

Re: How to uncompress a zip file which has a folder in Nifi?

@Shu Thanks for the response.I tried changing the path attribute by providing it with test/test_folder.I used update attribute I coulde see that the initial path was '/'.After Update attribute it changed to test/test_folder.But the unpack still goes to failure condition.It gives an an unsupported zip feature extension and descriptor not supported.

Re: How to uncompress a zip file which has a folder in Nifi?

Super Guru
@vinayak krishnan

I think you are using Packaging Format "ZIP" in your Second UnpackContent processor i.e after merge content processor.

Merge content processor adds mime.type attribute with the value application/flowfile-v3 (or)... etc, based on Merge Format property value in Merge Content processor.

In second UnpackContent processor we need to use either

Packaging Format

use mime.type attribute

(or)

Packaging Format

flowfile-stream-v3 //change the value based on merge format property value in Merge content processor

flowfile-v3 format generates .PKG flowfile from merge content processor, when we specify .zip as packaging format processor not able to unpack the contents because conflict in the packaging format.

If you are still having issues please attach the flow and config of processors screenshots, it will be helpful to find root cause.

Re: How to uncompress a zip file which has a folder in Nifi?

@Shu Sorry for the late response .The flow worked fine.As mentioned the unpack processor recursively extract all the files.When I make sample zip file it works fine.But unfortunately the ZIP file I have to work with has a descriptor.This cause the processor to fail and gives an unsupported feature exception.As workaround I am planning to write a script and call it via execute script processor.Will keep you updated on my progress

Don't have an account?
Coming from Hortonworks? Activate your account here