1

I have publicly accessible files in Salesforce (accessible by anyone, even without a Salesforce license), which can be accessed via URLs such as this:

https://XXXXXXXX.my.salesforce.com/sfc/p/#58000000Og0w/a/4H000001BDWe/FG3cuoiwxYaI_SGe9ZYC9swLPnX.88vSoqwtw9EgRH8

However, this is a page that displays the file with a download link. I would like to have a link to the file itself, without any HTML wrapping it. With googling I found that there are links like

https://<YOUR_SFDC_BASE_URL>/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX

that should do that, but they require a Content Version record Id, which always starts with 068. As you can see, the original URL does not contain something like that. Is there a way to programmatically derive the second URL from the first URL?

UPDATE: Yrc Shk suggests to use the DistributionPublicUrl object. Creating such an object from a ContentVersion gives you several URLs:

  • ContentDownloadUrl
  • DistributionPublicUrl
  • PdfDownloadUrl

Where DistributionPublicUrl is the URL that I started with, the page that allows you to download a file. The other two URLs appear to be the ones linked to the two Download buttons on that page.

But what I am really looking for, I'll say it more carefully now, is a URL to a page that displays just the file, without an HTML wrapper, without automatic downloading (a user might choose to download using the browser).

1 Answer 1

4

This can be done through ContentDownloadUrl, not to be confused with DistributionPublicUrl. The container URL you see is the DistributionPublicUrl, however the actual file URL can be found in ContentDownloadUrl.

You can read how to generate the URL in the below blogpost -

Generating Public URL for Salesforce Files

4
  • 1
    This is close, but actually a step too far. DistributionPublicUrl gives a URL that immediately downloads the file, without showing it in the browser. I guessed the phrasing of my question led you in this direction. I will modify my question. Commented Feb 16, 2022 at 11:15
  • If I understood it correctly, you want to have file preview capability without the Salesforce header. Assuming a custom file preview application, I'd say directly it is not possible. But, with help of javascript and customization, it can be achieved. If you see the downloadable link is nothing but streams of data bytes, and it can be gathered via JS promises and rendered as appropriate type with custom HTML code. (it can be very tough if type of files is diverse).
    – Ysr Shk
    Commented Feb 16, 2022 at 13:27
  • @SanderdeJong You able to find anything for this? I am generating one xml file and need to preview it. Commented Mar 12 at 12:57
  • @AaryaTiwary Sorry, no. Commented Mar 13 at 7:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .