20

I spend hours to find a way to control download behavior of pdf-files (when to download and when to show inline) and did not find anything.

What I got so far:

the main thing that do all files magic is

/sfc/servlet.shepherd/ ....

  1. We can download file by:

    • ContentVersion Id - /sfc/servlet.shepherd/version/download/<VERSION>
    • ContentDocument Id - /sfc/servlet.shepherd/document/download/<DOCUMENT>
    • Zip archive by Ids separated by slash - /sfc/servlet.shepherd/version/download/<VERSION 1>/<VERSION 2>?
  2. For some reason in salesforce download links we can find the following parameter operationContext=S1 OR operationContext=CHATER, which seems do nothing

  3. Also servlet.shepherd can show preview image of pdf /sfc/servlet.shepherd/version/renditionDownload?rendition=SVGZ&versionId=<VERSION>, where ?rendition= can be:

    • SVGZ
    • THUMB120BY90
    • THUMB240BY180
    • THUMB720BY480

All these options are not covered by official documentation and I feel there could be much more features. Does anybody know other options? Is there any documentation explaining all possible options?

UPD: Added option with multiple files download as a zip provided by @cropredy

4
  • I would love to know if we can force inline behavior vs download, for pdfs I want it to open in browser window but it seems to just download the document and then the user has to click the download to open it. Feb 12 '19 at 14:31
  • @ScottMorrison, I don't think you can change that behavior programatically, but if you have a Visualforce page rendered as a PDF you can set 'content-disposition' header on the Visualforce page to determine what the browser does with it and there are also settings under "Setup" > "Security" > "File Upload and Download Security" to change how certain file extensions are handled by default within Salesforce (ex. ".pdf => download" or ".mp4 => execute in browser")
    – nbrown
    May 13 '20 at 23:33
  • Though the hardcoded URL method works, it isn't officially supported. So i would request you upvote this idea https://trailblazer.salesforce.com/ideaView?id=0874V000000PiVqQAK and share it as well. Direct access to the images will be really helpful for use in custom applications and components. Aug 1 '20 at 19:18
  • 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 . Sep 23 '20 at 10:24
11

Looks like there are some changes recently. I am seeing below pattern with API version 48

For authenticated users

/sfc/servlet.shepherd/document/download/06955000001UrOPAA0

For communities

/sfsites/c/sfc/servlet.shepherd/document/download/06955000001UrOPAA0

ID in the URL being content document ID.

1
  • Thank you a ton. I didn't realize the communities url was prefixed now. Jun 26 '20 at 18:58
10

You can also download multiple files as a zip

{!URLFOR('/sfc/servlet.shepherd/version/download/' & delimitedSelectedIdList &'?')}

example:

{!URLFOR('/sfc/servlet.shepherd/version/download/068xxxxxxxxxxxxxxx/068yyyyyyyyyyyyyyy?')}

more details on my blog

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