function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Read zip attachments

Please suggest how can I read a zip attachment from the VF page. The attachment consists of some text files. Currently I am reading it via zip.js library but it gives a cross domain accessibility error since the attachments are in a different sub domain.

Please suggess a way out!!
PrasanntaPrasannta (Salesforce Developers) 

In order to read the Read zip attachments, Please include JSzip library in the javascript function.

Here is the example of the javascript code snippet-
function viewContent(){
        var zip = null;
        var zipFileName = null;
        var zipFileNames = null;
        data = "{!contentAsText}";
        zip = new JSZip(data, {base64:true});
            zipFileName = '';
            zipFileNames = [];
            for(var zipfileName in zip.files){
         if(zipfileName == 'index.html'){ 
         var file = zip.files[zipfileName];
         var data =;
         document.getElementById('contentdiv').innerHTML = data;
         //var data = JSZipBase64.encode(;
n controller --

public String contentAsText {get;set;}

List<Attachment> atts = [Select Id, Body from Attachment where name='' limit 1];
       contentAsText = EncodingUtil.base64Encode(atts[0].Body);
Hope this helps.
Pedro I Dal ColPedro I Dal Col
You can try using Zippex ( It's an open source zip library for Apex. You can load the zip files using an HttpRequest in the controller and uncompress them using Zippex before you display the results in the page.