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
ihssan tazinyihssan taziny 

How to process a HttpResponse blob zip file

In my application, i am sending an HttpRequest to an external server to get a zip file, and once it's done i get the response as Blob, but i don't know how to process the Blob to extract some files from it.
This is the code:
HttpRequest request = new HttpRequest();

 /* Here i set the Endpoint, body, and method attributes*/

Http http = new Http();                
HttpResponse response = http.send(request);

 Blob file = response.getBodyAsBlob();

/*Here i should process the Blob (which is a zip file) to extract my files*/
Help please.. !!
 
Best Answer chosen by ihssan taziny
ihssan tazinyihssan taziny
I finally found an answer to deal with this problem, i posted it in Stackoverflow. Here's the link: http://stackoverflow.com/questions/31993430/salesforce-extract-files-within-blob-zip-file

It's a work-arround: I create a StaticResource with the Metadata API of salesforce, but before i had to add a new Remote Site with the current instance of Salesforce.  to be able to call the method of the API.
Then i create a PageReference Object with the content of the file name within the StaticResource zip file.

All Answers

RAM AnisettiRAM Anisetti
ihssan tazinyihssan taziny
thanks for your answer. But the links doesn't help me. In fact is there a way to unzip the file via an External API??
ihssan tazinyihssan taziny
I finally found an answer to deal with this problem, i posted it in Stackoverflow. Here's the link: http://stackoverflow.com/questions/31993430/salesforce-extract-files-within-blob-zip-file

It's a work-arround: I create a StaticResource with the Metadata API of salesforce, but before i had to add a new Remote Site with the current instance of Salesforce.  to be able to call the method of the API.
Then i create a PageReference Object with the content of the file name within the StaticResource zip file.
This was selected as the best answer
Pedro I Dal ColPedro I Dal Col
This can be done with the Zippex library. It's open source and available here https://github.com/pdalcol/Zippex
 
HttpRequest request = new HttpRequest();

//Set the Endpoint, body, and method attributes

Http http = new Http();                
HttpResponse response = http.send(request);

Blob file = response.getBodyAsBlob();

//Instantiate Zippex with zip file Blob
Zippex zip = Zippex(file);

for (String fileName : zip.getFileNames()) {	
    //Extract file
    Blob fileData = zip.getFile(fileName);
    //Process the file here
    ...
}