cancel
Showing results for 
Search instead for 
Did you mean: 

How to find if the uloaded file is a zip file

Former Member
0 Kudos

Hello everyone,

I am currently implementing a filter in my code where I put a restriction that allows only a certain type of files to be accepted. One of them is the zip file type.

However, when I tried to read the mimetype of this zip file using the folloing API :

IWDResource.getResourceType().getHtmlMime(),

I get "application/octet-stream" which is the mime type of any binary file, and not "application/zip" which is the usual zip file mimetype.

Therefore it is difficult to identify whether the uploaded file is a zip file which we can operate on accordingly.

I need to know whether there is some way I can acheive this?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You can check with File extension to know whether it is zip file or not.

Use this code.. Here "reso" is of binary type which is bound to data property of FileUpload UI Element.

IWDAttributeInfo attributeinfo=wdContext.getNodeInfo().getAttribute(wdContext.currentContextElement().RESOURCE);

IWDModifiableBinaryType binType=(IWDModifiableBinaryType)attributeinfo.getModifiableSimpleType();

String ext=binType.getMimeType().getFileExtension();

if(ext.equalsIgnoreCase("zip"))

// Code when it is zip file

else

// Code when it is not

Regards

LN

Former Member
0 Kudos

Hi Dhruwat

there is a java-api called [truezip|https://truezip.dev.java.net]

in which you will find the following class ZipDetector, and the method "isZipFile".

[https://truezip.dev.java.net/javadoc-5/de/schlichtherle/io/ZipDetector.html#isZipFile(java.lang.String)]

Or something other but i don't know if you can find out that.

Every (regular) zip has the encoding "CP437". Maybe you can

check the outputstreams-encoding..?

Regards