0

1) Has anyone done a comparison of JSZip and Zippex? If so could you give me your opinions?


Context for next question

This is all occurring in visualforce pages, and in apex code.

I'll briefly describe the intended workflow with Zippex installed.

1) (VFP) - Admin clicks on "generate PDFs" button

2) (APXC) - generates the PDFs in a for loop, in which they are attached to the zippex file

3) (VFP) - a visualforce page is returned from which opens the prompt for the admin to download the zip file.


Current workflow.

1) (VFP) - Admin clicks on "generate PDFs" button

2) (APXC) - generates the PDFs in a for loop, but returns the last generated one (the pageRef is defined outside the loop)

3) (VFP) - a visualforce PDF page is returned, from which the file downloaded prompt automatically opens

Questions

1) How do I return a zip file and prompt the download? I tried returning Zippex but I got

Return type of an Apex action method must be a PageReference

So how do I return a page with that on it?

1

1) Has anyone done a comparison of JSZip and Zippex? If so could you give me your opinions?

Apex Code isn't particularly good at binary, except for those precious few methods that use binary tasks (like the Crypto methods), and that will likely remain true for the foreseeable future. Use JSZip if you care about performance. If the file sizes are pretty small, though, the difference is negligible and should not be considered a serious factor.

While Zippex is really cool in principle, the limits in terms of CPU time and heap size, as well as the general lack of proper binary data support, makes it less than ideal. While we don't generally answer "opinion-based" questions, I'm pretty sure anyone that's actually done any work with binary data in Apex Code is likely to agree.

P.S. Go vote on this idea. Native ZIP file access would be awesome for everyone.


You can only return a PageReference in an action method. In other words, you don't want to do this. Instead, you'd want to provide the data inline. Here's one theoretical design:


public class ZipController {
    public transient String base64Zip { get; set; }
    public void prepareZipFile() {
        Zippex zipFile = new Zippex();
        // prepare/populate Zip file
        base64Zip = EncodingUtil.base64Encode(zipFile.getZipFile());
    }
}

<apex:page controller="ZipController">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:commandButton action="{!prepareZipFile}" value="Prepare" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection>
                <apex:outputText rendered="{!NOT(ISBLANK(base64zip))}">
                     <a href="data:application/zip;base64,{!base64zip}" download="export.zip">Download</a>
                </apex:outputText>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.