I am trying to unzip a zip file attachment. but, unable to unzip the attachment and process all the internal files in the zip file. I want to do this using an email handler class.


You can do this natively in Apex using the Zippex library which is open source. https://github.com/pdalcol/Zippex

Your code would be similar to this:

Blob zipBlob; //This needs to contain the zip file

Zippex myZip = new Zippex(zipBlob);

//Loop through the files in Zip and process them
for (String fileName : myZip.getFileNames()) {

    Blob fileData = myZip.getFile(fileName);

    //Process fileData here.

  • Pedro, Thank you for sharing this. This is exactly what I was looking for....Very cool! – Carlos Jul 19 '16 at 22:17

Unfortunately, there is no native zip support in APEX right now. But you can help yourself using a very good Javascript zip tool like http://stuk.github.io/jszip/

On how to use it, look at http://andyinthecloud.com/2012/11/04/handling-office-files-and-zip-files-in-apex-part-1/

and http://andyinthecloud.com/category/zip/

  • 1
    Close, but it won't work for apex code. However, I'm working on a batch class version since the new ten minute limit was introduced. – sfdcfox Jul 12 '14 at 15:04
  • @sfdcfox sounds very interesting. Will you share your approach? Can you elaborate on how you do it or post a link? – Uwe Heim Jul 12 '14 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.