Salesforce enables you to display/share images stored as Salesforce files, outside Salesforce by using the ContentDelivery object. For a public exposure of the file just create a record with the ContentDistribution object along with a link to the specific ContentVersionID.
In this blog, you will learn how to download and preview images/documents on-site with the help of ContentDistribution Object. First, let us find out what is contentdistribution all about?
What Is ContentDistribution?
Salesforce provides standard object contentdistribution. It is available in API version 32.0 and later. Content Version represents a specific version of a document in Salesforce CRM Content or Salesforce Files. ContentDistribution contains ContentVersionID which links the content version object and helps to download the images and documents. It is provided with the external link for download/preview images as well as documents. The API of contentdistribution is ContentDistribution. ContentDistribution represents information related to sharing a document externally in Salesforce.
Next, we will deal with the steps to download the images.
How To Download An Image?
Here is the setup for downloading/previewing the image on site.
- Fetch the content version.
- Insert ContentDistribution with particular ContentVersionID.
- Fetch the contentdistribution with the help of ContentVersionID.
- Then you insert the ContentDistribution.
- After the contentdistribution is inserted then you fetch the contentdistribution with DistributionPublicUrl, ContentDownloadUrl fields.
- Preview the images on-site with the DistributionPublicUrl field provides the URL.
- Download the images on-site with Url from the ContentDownloadUrl field
Here are some queries to fetch content version and contentdistribution,
Queries to Fetch Version and ContentDistribution
- Fetch Content Version:
Select Id, ContentDocumentId, Title FROM ContentVersion,
- Fetch the ContentDistribution:
SELECT Id,Name, ContentDownloadUrl, ContentDocumentId, DistributionPublicUrl, ExpiryDate, PreferencesAllowViewInBrowser
We can use ContentDistribution to get ContentDownloadURL for images that are stored in Salesforce Files. The ContentDownloadUrl provides the URL for download on-site and the DistributionPublicUrl is provided by the ContentDistribution, a public URL for Previewing the images/Documents on the Site.
Here are some screenshots of code snippets.
Code Snippets ScreenShots
In the below screenshots, we have specified steps on how to download/Preview the image/document on site.
Some screenshots on how to Download and Preview the images
For previewing the images as well as the documents.
Finally, you can have a look at the demo Video to Download and Preview the images as well as Documents with the following link:
Salesforce enables you to display/share images stored as Salesforce files, outside Salesforce by using the ContentDelivery object and provides standard object contentdistribution. It is available in API version 32.0 and later. ContentVersion represents a specific version of a Salesforce CRM Content or Salesforce Files. ContentDistribution links the content version object and helps to download the images or documents with the external link for download/preview images as well as documents.
Get in touch with the expert team of Cloud Analogy who will assist you in gaining better operational management and creating a single view of your consumer.