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
ericszulcericszulc 

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,

e.

Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

Here is a working example: 

 

http://sitesdemo.force.com/abtest

 

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

HeathLongHeathLong

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

BulentBulent

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="window.open('https://na7.salesforce.com/sfc/#version?selectedDocumentId={!contentDoc.doc.ContentDocumentId}')">{!contentDoc.doc.Title}</apex:outputLink>

 

<apex:outputLink value="#" onclick="window.open('http://abc.force.com/sitepath/sfc/#version?selectedDocumentId={!contentDoc.doc.ContentDocumentId}')">{!contentDoc.doc.Title}</apex:outputLink>

 where abc.force.com/path/is 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

 

 

Walter@AdicioWalter@Adicio

thank you. this thread gave me ideas.

icemft99icemft99

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.

[ http://eduventures.force.com/europe/sfc/#version?selectedDocumentId=06980000000DHKZAA4
dev401hasdev401has

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

What about the 'Guest' licences?

 

BulentBulent

 

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

 

dev401hasdev401has

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.

BulentBulent

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

dev401hasdev401has

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

https://cs3.salesforce.com/sfc/#version?selectedDocumentId=069XXXXXXXXXXXX it comes up with that error about Insufficient Privileges.

 

If with this URL https://cs3.salesforce.com/sfc/servlet.shepherd/version/download/068XXXXXXXXXXXX?asPDF=true

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?


BulentBulent

Here is a working example: 

 

http://sitesdemo.force.com/abtest

 

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
dev401hasdev401has

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 - http://viewer.zoho.com/home.do that requires the url to the document rather than in 
"/abtest/sfc/servlet.shepherd/version/download/06830000000B9dP" format.
BulentBulent

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?

 

Thanks,

 

Matt

 

jgibbjgibb

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:
http://TheSiteURLGoesHere/sfc/servlet.shepherd/version/download/ContentVersionIDGoesHere
Nothing is returned -- no file, no error. Why did this stop working?
Jason

 

sdurairajsdurairaj

Jason,

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.

 

Thanks,

Sathish

jgibbjgibb

Sathish,

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.

sdurairajsdurairaj

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?

jgibbjgibb

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.

JVIowaJVIowa

Any update from tier 3 on this? 

jgibbjgibb

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.

svittalasvittala

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?

 

ClydeSavageClydeSavage

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

 

Thanks

jgibbjgibb

Clyde,

 

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:

 

http://boards.developerforce.com/t5/Force-com-Sites/Make-ContentVersion-downloadable-accessible-via-Sites/m-p/239725#M4262

 

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

 

Regards.

SathyaincampusSathyaincampus

 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 :-

<SiteURL>/sfc/servlet.shepherd/version/download/<MyDocumentId>

 

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

 

Regards

Sathya

SathyaincampusSathyaincampus

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)

http://<siteurl>/<siteprefix>/sfc/servlet.shepherd/version/download/<ContentVersionId>?asPdf=false&

 

Thanks everyone.

mirunmirun

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.

 

Thanks.

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 : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdistribution.htm
object, 

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 ];
                    if(cdList.size()>0){
                      return cdList.get(0).ContentDownloadUrl;
                    }else{
                        ContentDistribution newItem = new ContentDistribution();
                        newItem.Name = cv.Title;
                        newItem.ContentVersionId = cv.Id;
                        newItem.PreferencesAllowViewInBrowser= true;
                        newItem.PreferencesLinkLatestVersion=true;
                        newItem.PreferencesNotifyOnVisit=false;
                        newItem.PreferencesPasswordRequired=false;
                        newItem.PreferencesAllowOriginalDownload= true;
                        Insert NewItem;
                        
                        newItem = [SELECT ID,DistributionPublicUrl, ContentDownloadURL  from  ContentDistribution               where ID= :newItem.Id];
                     
                        return newItem.ContentDownloadURL;
                    }
Hope this helps