+ Start a Discussion
Mohammed AzarudeenMohammed Azarudeen 

How do I Loop Through All the Images in Zip file in Controller

I have one static resource zip file, which has N number of Images. So I don't know the exact number of images are present in zip file.
I just want loop through all the images in zip file. How can I achieve this?. Any help is appreciable.
My VFP page is,

<apex:page Controller="repeatCon">
<body style="font-size:10pt; font-family:sans-serif">
            <td style="font-family:'Segoe UI', Tahoma, sans-serif;">
                <apex:repeat value="{!imageList}" var="img">
                    <td><apex:image url="{!URLFOR($Resource.MinionsDemo,img)}" height="200" width="200" /><br/></td>

and my controller class is,
public class repeatCon {
    public List<string> getimageList(){
        List<String> imgstr = new List<String>();
        for(integer i = 1; i <= zipfileimagesize; i++){
    return imgstr;
in the loop how do I give the size of images present in zip file
You may be able to do this by pulling files from the zip as PageReferences. Andy Fawcett introduced this in his blog post : http://andyinthecloud.com/2012/11/04/handling-office-files-and-zip-files-in-apex-part-1/

The concept is :
PageReference somefileRef = 
   new PageReference('/resources/myzip/folder/file.js');
Blob contentAsBlob = somefileRef.getContent();
String contentAsText = contextAsBlob.toString();

However, getContent calls are counted as callouts so you may need multiple requests to figure out how many files you have. I suspect the only way that this will really scale will be a batch job that processes the file, figures out how many files are present and persists this in a custom object or setting.
Pedro I Dal ColPedro I Dal Col
Install the Zipex library. It's open source - you can get it here:  https://github.com/pdalcol/Zippex

Then you can use this code in your controller to read the name of the .jpg files inside your zip file:
public class repeatCon {
    public List<string> getimageList(){
        StaticResource staticRes = [SELECT Body FROM StaticResource WHERE Name = 'MinionsDemo'];
        Zippex minionsDemoZip = new Zippex(staticRes.Body);
        List<String> imgstr = new List<String>();
        for(String imgFileName : minionsDemoZip.getFileNames()){
        return imgstr;