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
Abhinav GuptaAbhinav Gupta 

Download document from Chatter ContentPost

Hello Everyone,

 

I am dealing with FeedPost (Type=ContentPost) with file attachments in a visualforce page. I need to render a download link for the document attached in the Feed Post. I can't use visualforce chatter tags.

 

Is their any other way similar to what we do for attachment, as shown in code snippet below.

 

 <apex:outputLink 
      value="{!URLFOR($Action.Attachment.Download,
                      attachment.id)}">
      Download Now!
 </apex:outputLink>

 

 

 

spaspa

assuming your feed is in "myfeed" and your controller is returning the link are you able to do the following.

 

<apex:outputLink value="{!myfeed.FeedPost.LinkUrl}">Download Now!</apex:outputLink>

 

 

see the last example in the recipes.

 

http://wiki.developerforce.com/index.php/Chatter_Code_Recipes

 

cloudcodercloudcoder

You might also want to check out the new Objects and features for accessing Chatter files in Spring 11. Check out the release notes for more info:

 

http://wiki.developerforce.com/index.php/Documentation#Release_Notes

LesKLesK

Well, there is another, slightly unorthodox way to do this until Salesforce exposes the Doc/Attachment ID via the API.

 

What you can do now is to scrape the Chatter page to get the DocId and then use that construct the Download link. Please keep in mind that this may break in the future or if/when Salesforce decides to change the download URL, though...

 

Anyway, here is how to do it:

 

1.) Pass your feedPostId to the link.

2.) We consume the page, which only displays one chatter post, and search for distinguishing markup in the page, specifially the "feeditemtext".

3.) Find the download URL and find a distinguishing end to the link ("?asPdf" in our case).

4.) Return the substring.

 

 

 

 

    public String findLink(String feedPostId) {
        PageReference myPage = new PageReference('https://tapp0.salesforce.com/_ui/core/userprofile/UserProfilePage?ChatterFeedItemId=' + feedPostId);
        String content = myPage.getContent().toString();
        Integer startIndex = content.indexOf('feeditemtext');
        startIndex = content.indexOf('https://c.cs0.content.force.com/sfc/servlet.shepherd/version/download/', startindex);
        System.debug('********** start ' + startIndex);
        Integer lastIndex = content.indexOf('?asPdf', startIndex);
        System.debug('********** end ' + lastIndex);
return content.substring(startindex, lastIndex)); 
    }
 

 

 

We're missing try/catch, but as a proof on concept/stopgap, this will work for now.