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

Make ContentVersion downloadable/accessible via Sites

Hello Everyone,


I'm trying to make some files we uploaded into salesforce crm content downloadable or accessible by another page via Sites. For instance, say, an mp3, either downloaded or requested by mediaplayer on a webpage.


According to the docs 'To download a document via the API, you must export the VersionData of the document.'


Well... I've tried a couple variations with a visualforce page to retrieve/export the contentversion, but (as expected) no luck.


Does anyone have any good ideas on how to do this?


Thanks in advance,


Best Answer chosen by Admin (Salesforce Developers) 

Here is a working example:


The link on this page would look like this (the format is different than what I posted before, sorry)



  <apex:outputLink value="/abtest/sfc/servlet.shepherd/version/download/06830000000B9dP" target="_document">testdoc</apex:outputLink>



All Answers


5 months and not a word? I am having a problem with this as well.


you need to create a custom controller and using content api retrieve the content id.

once you do this on your visual force page you can create a link like following



<apex:outputLink value="#" onclick="'{!contentDoc.doc.ContentDocumentId}')">{!contentDoc.doc.Title}</apex:outputLink>


<apex:outputLink value="#" onclick="'{!contentDoc.doc.ContentDocumentId}')">{!contentDoc.doc.Title}</apex:outputLink>

 where your site url

and assume that you return the content document id via the contentDoc.doc.ContentDocumentId from your controller


you might have doe this much so far. the missing piece in our case might be the content workspace access


you need to create a public group and add your site user to this public group.

and finally you need to add this public group to your content workspace so that your site will have read access to the content workspace




thank you. this thread gave me ideas.


But aren't Sites users 'guest' licenses (i.e. can't view Salesforce CRM Content )?


When I do this I get the following message:


Insufficient Privileges
You are not a licensed Salesforce CRM Content user.
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.


Yes. I am facing same problem too. I too get the same error msg as above!

What about the 'Guest' licences?




Code snippet: 
VF Page: 
<apex:outputlink value="{!ContentURL}">File</apex:outputlink> 
Apex (Hard coded document): 
public PageReference getContentURL() 
ContentVersion []cv=[select id, ContentDocumentId from ContentVersion where contentdocumentid='06930000000TnHP']; 
return new PageReference('/' + cv[0].id); 
you need to use the version id in the code 
you need to create a public group and add your site user to this public group.
and finally you need to add this public group to your content workspace so that your site will have read access to the content workspace

Code snippet: 

VF Page: 
<apex:outputlink value="{!ContentURL}">File</apex:outputlink>
Apex (Hard coded document): 

public PageReference getContentURL() { 

 ContentVersion []cv=[select id, ContentDocumentId from ContentVersion where contentdocumentid='06930000000TnHP']; 

return new PageReference('/' + cv[0].id); 



you need to use the version id in the code 
you need to create a public group and add your site user to this public group.and finally you need to add this public group to your content workspace so that your site will have read access to the content workspace



Hi Bulent Cinarkaya


Thanks for the quick reply.

What i understood from your reply is that the user will have access to Content Document object from the steps i follow about creating public group and all.

but when on site, i will click on the link it will ask for ID and password and this will get restricted to salesforce users only.

My Site will be public and should be accesible to all users instead of only salesforce users.

hence i am using Content delivery. Salesforce generates the URL which is accessible to all users without ID/Password but i am not able to retrieve it dynamically. I have to hard code it in my VF page of site.

Can you provide a solution so that it is available for all users instead of only salesforce users or how can i dynamically fetch the URL of content delivery into my site.


the example I provided works for public sites, and not specific to authenticated users.


Hi Bulent


Thanks again for the quick turnaround.

I would like a deeper insight then.

I would elaborate what i am facing and why i believe it is restricted to salesforce user.


I did all the steps of creating the group and adding it as reader in my workspace. But the guest site  user which i added does not have the access to Salesforce CRM content. So when i click on the following link it comes up with that error about Insufficient Privileges.


If with this URL

then it asks for ID and password.


I believe i need to get that Salesforce CRM content checkbox checked then only i can access the workspace and I am not able to get that done in Guest license site user. So i think only salesforce users who have access to salesforce crm content can use it other site user cannot.


can you please explain in detail?


Here is a working example:


The link on this page would look like this (the format is different than what I posted before, sorry)



  <apex:outputLink value="/abtest/sfc/servlet.shepherd/version/download/06830000000B9dP" target="_document">testdoc</apex:outputLink>



This was selected as the best answer

Hi Bulent


Thanks for the quick reply again.


That was great solution.

I was doing silly mistake for the URL that was restriciting me.


Thanks a lot.

Juda MartoJuda Marto

Hi Bulent,


Is it possible to get the url of the document from the sfc.shepherd servlet? I need to pass it to an embedded document viewer such as Zoho Viewer - that requires the url to the document rather than in 
"/abtest/sfc/servlet.shepherd/version/download/06830000000B9dP" format.

there is no other url to access content.

Matt LaceyMatt Lacey

Hi Bulent,


I have been trying to use this method and have so far been unsuccessful - we even though I'm accessing it via sites as an authenticated user I get taken to the login screen for the org. Presumably this is because the "Salesforce CRM Content User" checkbox is unmarked for the portal user I am using, however this box is disabled on the user's edit page - I am an Administrator on the org and CRM Content is enabled as we have a document in it.


The end game is that we're trying to serve up content in an iframe on a visualforce page on the site, preferably using the preview functionality accessible when you create a content delivery, but apart from not being able to get the URL for that even the method in this thread isn't working for these users.


Any ideas?







This method to access a content file via a public URL appears to be broken with the Spring 2011 release. Can anyone confirm this? It was working fine until the release, then it stopped working. Here's how we have it set up:


1. Create a site
2. Create a public group
3. Associate the site's guest user to the public group
4. Associate the public group to a workspace
5. Upload a file to the workspace (which creates a ContentDocument with a corresponding ContentVersion record)
6. Get the ContentVersion ID and plug it into this URL:
Nothing is returned -- no file, no error. Why did this stop working?




Do you have any updates on this? I set up as indicated in the thread for couple of days now on Spring '11 and I've been getting same response. No Error and no document. Let me know if you hear about a fix.






No answer yet, but we just opened a case with Salesforce support (case number 04300024). I'll post here if I hear of a solution. I'm hoping the URL just changed and they haven't notified anyone yet.


Thank you so much. Hope you get a response soon.


With this solution, were you able to open a Content document to public user wihtout logging into Salesforce prior to Spring '11 upgrade?


Here's the latest feedback from Salesforce support (not very reassuring):


Your case has been escalated to Tier 3 and the original determination is that this is considered to be a type of url hacking and was never officially supported.

As this is functioning as expected, I will be reducing the severity level to 3 as Tier 3 continues investigating any possible workarounds for this.

In general, providing content to sites public users from Content or Documents was never officially supported. The only officially supported mechanism is via Static resources.

I will keep you updated on Tier 3’s progress on a possible workaround.


Any update from tier 3 on this? 


Good news! According to Tier 3 support, the issue has been resolved for the Spring 2011 release. I just confirmed that the content URLs appear to be working correctly on one of our Spring 2011 production orgs.


I tried this approach. This allows me to download the content.. I would like to use the Preview functioanlity that is available in SFDC.. Is that possible to expose the content with the Preview Mode?



What approach?  Can someone please give a clear and concise definitive answer and solution?






Read the full thread of this discussion from the beginning and you'll find sample code and step-by-step instructions. For example, my earlier instructions now work correctly -- see Message 16 on this page:


We've been told by Salesforce support that this undocumented feature will continue to be supported in future releases.




 I am facing the same issue now. Need to access/download the Salesforce CRM Content Document from within Sites (using Partner portal authentication). Can you please let me know how we can do that? Can this be done now?


We are trying to access the document using this url :-



is this correct? but its not working :(   please help..





Crazy... I found the issue :D

it was my mistake.. 

There are two objects, one is contentversion and another is contentdocument.

I was giving the id of contentdocument (in place of <contentversionid>) in the below url.. when i changed it to contentversion id it downloaded the document from the sites (authenticated through partner portal)



Thanks everyone.


Hi All,

Is there any option to download or view the video file (uploaded in salesforce crm) via chatter api.

Please guide me around...Oauth authentication has been done but iam unable to find any clear step whether download a video file(say mp4 file) can be done via api.



Lester Garcia - NewsporeLester Garcia - Newspore
Hi All. 

did Found a Way to enable it to Guest Licenses. but it will require for you Salesforce CRM Content setting to have Public Links. 
Basically is using this :

What I did is Create a Content Distribution for the Content Version and then after Creating it, you must get the ContentDownloadURL in the Image Source of the Site that you want and there you go. 

Please look at this simple Example: 
public Static String getImageURL(ID LatersPublishedVersionID){
ContentVersion cv = [SELECT ID , ContentDocumentID from ContentVersion where ID= :LatestPublishedVersionId];

List<ContentDistribution> cdList = [select ID,DistributionPublicUrl ,ContentDownloadURL  from ContentDistribution where ContentVersionId= :cv.Id and ContentDocumentId=:cv.ContentDocumentId ];
                      return cdList.get(0).ContentDownloadUrl;
                        ContentDistribution newItem = new ContentDistribution();
                        newItem.Name = cv.Title;
                        newItem.ContentVersionId = cv.Id;
                        newItem.PreferencesAllowViewInBrowser= true;
                        newItem.PreferencesAllowOriginalDownload= true;
                        Insert NewItem;
                        newItem = [SELECT ID,DistributionPublicUrl, ContentDownloadURL  from  ContentDistribution               where ID= :newItem.Id];
                        return newItem.ContentDownloadURL;
Hope this helps