+ Start a Discussion

Handling a download in Visualforce

I'm building out a visual force page that collects the attachments from a case, stores them temporarily in a transient list of attachment objects, and then bundles them into a zip file by passing them into a javascript method using merge syntax.


My question is that once I have the file created where is it stored? Is there a specific location that transient files are stored, if so what is it? I need to know where they're going before I can initiate the download...




I realized that it may help if I give you code.



<apex:page showHeader="false" StandardController="Case" extensions="AtchmntDownloader">

<script type="text/javascript" src="jszip.js"></script>

<script type="text/javascript" src="jszip-deflate.js"></script> 

<script type="text/javascript">     

funtion createZip(){         

var allAttachments = new JSZip();         

allAttachments.add("Hello.txt", "Hello World\n");         

content = allAttachments.generate();         

location.href = "data:application/zip;base64;"+ content;     


<body onload="javascript&colon; createZip()">     

{!Count} Attachments found<br/>     

Please wait, assembling Zip file...<br/>     

<apex:dataList value="{!Names}" var="String">{!String}<br/></apex:dataList> 






public with sharing class AtchmntDownloader {

Public Case CaseRef {get; set;}

Public transient List<Attachment> Attachments {get; set;}

Private Id thisID {get; set;}

Public List<String> Names {get; set;}

Public Integer Count {get; set;}
    public AtchmntDownloader(ApexPages.StandardController controller) {

        CaseRef = (Case)controller.getRecord();

        thisID = CaseRef.Id;

        Attachments = [Select Name, ContentType, BodyLength, Body From Attachment WHERE ParentId = :thisID];       

Names = new List<String>();

        Count = 0;       

for(Attachment li: Attachments){







The hello world file is just there for testing purposes, so you can ignore it. It's really the zip download delivery I can't get to work.....




This code is working for firefox but not working with chrome and IE.

some memory issuse when download more than 2000 KB.

Plz look into this.


Thanks in Advance




Try replacing this:

var allAttachments = new JSZip();         

allAttachments.add("Hello.txt", "Hello World\n");         

content = allAttachments.generate();         

location.href = "data:application/zip;base64;"+ content;     


with this:

var zip = new JSZip();
zip.file("Hello.txt", "Hello World\n");
var img = zip.folder("images");
img.file("smile.gif", imgData, {base64: true});
var content = zip.generate();


This might still not work for chrome and IE. I did this over a year ago and don't remember how I solved the issue, but using the /file method over the .add method is much more efficient and might solve some problems.