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
Erhan FIRATErhan FIRAT 

How to download file from a callout in Apex?

Hi all,
I have a problem and cant found any solution to this. There is a callout from Apex side to my webservice. Service returns the file as zipped. And then I want to download this file.

Here is code:
    public String getZipFile(String endpointUrl, String jsonStr){            
        HttpRequest reqData = new HttpRequest();
        Http http = new Http();
        
        reqData.setHeader('Content-Type','application/json');
        reqData.setHeader('Connection','keep-alive');
        reqData.setHeader('Content-Length','0');
        reqData.setTimeout(20000);
        
        reqData.setEndpoint(endpointURL);
        reqData.setBody(jsonStr);
        reqData.setMethod('POST');
        
        try {
            HTTPResponse res = http.send(reqData);
            Blob zipBlob = res.getBodyAsBlob();
            zipFileEncoded = EncodingUtil.base64Encode(zipBlob);
            system.debug('zipBlob >>>>>>>>>>>>>> ' + zipBlob.toString());
            system.debug('zipFileEncoded >>>>>>>>>>>>>> ' + zipFileEncoded);
            return zipFileEncoded;
        }catch(Exception exp){
            System.debug('exception ' + exp);
            return exp.getMessage();
        }
    }

 

And the VisualForce side, what should I do? Now, I have just call the action. Is there anything?