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
Rachit JoshiRachit Joshi 

Download multiple files as zip from ContentVersion

I found this link https://developer.salesforce.com/blogs/engineering/2014/04/building-content-rich-visualforce-pages-with-salesforce-crm-content.html to download multiple files as .zip from ContentVersion.

Can we use /sfc/servlet.shepherd/version/download/ to download multiple files?
Since this is not documented in any of the salesforce docs.
NagendraNagendra (Salesforce Developers) 
Hi Joshi,

Sorry for this issue you are facing.

Download multiple ContentVersion files as Zip:

In our org, there is a related list underneath the Contract object of ContentVersions of the contract and any amendments. Users wanted to be able to download all (or download selected) files with one click.
Such relatedList does not provide any download button. You need to select each file in turn, go to the Content page and click Download. Tedious. Users hated it. I hated it.

Googling revealed an interesting post on downloading attachments into a zip http://www.valnavjo.com/blog/compressing-files-in-salesforce/ using JSZip. However, we had files greater than 15MB and I worried about Heap Limits.

Turns out SFDC provides download ContentVersion as zip already on the Content tab. (Where our users nor I almost never go as the Contract relatedList is more convenient). So, I used the browser developer Tools to see what URL was constructed by SFDC and saw that it exploited the undocumented servlet.shepherd.

The specific URL to use is:
{!URLFOR('/sfc/servlet.shepherd/version/download/' & delimitedSelectedIdList &'?')}
Where delimitedSelectedIdList is a list of ContentVersion ids separated by a forward slash. from my understanding, the ids separated by slashes is a sometimes-used REST convention to specify a list of resources.

Example (downloads 2 files into a single zip):
{!URLFOR('/sfc/servlet.shepherd/version/download/068xxxxxxxxxxxxxxx/068yyyyyyyyyyyyyyy?')}
Tested this on large zip files (~400 MB) and had no issues.

Notes:
  • servlet.shepherd is undocumented and hence unsupported so this might not be the right answer for a mission-critical application.
  • servlet.shepherd does not work on Attachments, only ContentVersion.

Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
Pawan sharma 24Pawan sharma 24
single click multiple PDF download only selected checkbox only Reply Soon.......
IT Support EnessIT Support Eness
Please beware that servlet.shepherd has problems with special characters: In case the file name contains special characters (e.g. äüö) a files name is changed to the Id of the ContentDocument/ContentVersion .
UMANG DADHANIYA 4UMANG DADHANIYA 4
How can I change the name of the Zip file?