I want to read a zip file from a give url. That zip file is having a XML file which is the main file which I want to access.

Is there a way to access/read that XML/Zip file ?


2 Answers 2


No, you can't natively decompress/read the contents of a ZIP file in Apex Code. Furthermore, given the inherent limitations of the platform, including the CPU time limit and lack of binary facilities, it's impossible to decompress any file over a couple of kilobytes in size. Preferably, you'll want to download the XML file directly, if possible.

MORE INFO: If you're willing (and able) to use JavaScript as a solution, you can use JSZIP to read the file, jQuery or any other JavaScript to download the file (through the JavaScript AJAX Proxy, if necessary). This will only run in a Visualforce or browser context (e.g. SControl, custom buttons), but it would allow you to read the ZIP file, which you can then read using jQuery's (or any other library/script) methods to parse and navigate the contained XML file. Also, since you're talking about client-side code, Flash, Java, and Silverlight are all viable options as well.

  • IS there a way to do this through javascript/jQuery ?
    – S.Sharma
    Commented Mar 30, 2014 at 16:04
  • @S.Sharma Didn't realize that was an option when I posted this. It is conceivably possible to do so with client-side scripting technology.
    – sfdcfox
    Commented Mar 30, 2014 at 16:45

You can do this natively in Apex with the Zippex library. It's open source and available here https://github.com/pdalcol/Zippex

//Fetch Zip file from URL
HttpRequest request = new HttpRequest();
HttpResponse response = new Http().send(request);
Blob zipFileBlob = response.getBodyAsBlob();

//Pass zipFileBlob to Zippex constructor
Zippex zip = Zippex(zipFileBlob);

//Extract sample_file.xml from zip archive
String xmlString = zip.getFile('sample_file.xml').toString();
  • You're right this is right way for download zip file
    – user108269
    Commented Dec 15, 2021 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .