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
goodtest123goodtest123 

How to get an uploaded file's link via feedpost?

Hi,

My Chatter feed has a file that was uploaded by someone. I have a remote application from where i am making webservices call to get the feedPost.

What I want to do is to create a link to this file so that the user can click on it to download directly from my remote application. I can get the name, id of the file etc from FeedPost, but I am not sure how to create URL

 

SELECT Id, Type,CreatedBy.FirstName, CreatedBy.LastName,ParentId, Parent.Name,FeedPost.Id, FeedPost.Type, FeedPost.Body, FeedPost.Title,(SELECT Id, FieldName, OldValue, NewValue FROM FeedTrackedChanges ORDER BY Id DESC),(SELECT Id, CommentBody, CreatedDate, CreatedById,CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments ORDER BY CreatedDate DESC LIMIT 4)FROM NewsFeed

 

Does anyone know how to do that?

Best Answer chosen by Admin (Salesforce Developers) 
jhartjhart

You just can't do it right now. In response to my logging a bug, Salesforce support suggests I "log it as an idea, and try to gather support for my Idea!".  But, I'm an engineer, not a politician, so in my opinion logging the bug should be sufficient - I shouldn't have to "gather support for my Idea!".

All Answers

jhartjhart

Are you sure you are getting the ID of the file?

 

As far as I can tell, the ID of the uploaded file is not exposed in the objects.

 

For example, when I upload a file to a lead feed, salesforce's chatter UI gives me a "Download" link to that file:

 

https://na7.salesforce.com/servlet/servlet.FileDownload?file=00PA0000000bYlQ

 

That's a pretty easy URL to construct ... if you know the file ID.

 

However, none of the FeedPost fields actually contain that ID.  None of the FeedPost fields (ContentData, Content FileName, etc) have the file ID, so salesforce has (perhaps unwittingly) not exposed that ID via their objects.

 

Thus, you cannot recreate that link.  Not quite a level playing field for 3rd party apps, as salesforce is clearly using "private APIs" to create their own UI.

 

Salesforce support - I have created case 03610581 to track this issue.

MfukahoriMfukahori

Hi, I had faced same case.

In case of current Summer '10 release, the uploaded file via chatter are stored in content.

 

Do you have any way to display that content URL in visualforce page?

 

I had checked the latest web API document, but there are not ContentDocumentId in FeedPost.

 

Thanks,

Madoka

jhartjhart

You just can't do it right now. In response to my logging a bug, Salesforce support suggests I "log it as an idea, and try to gather support for my Idea!".  But, I'm an engineer, not a politician, so in my opinion logging the bug should be sufficient - I shouldn't have to "gather support for my Idea!".

This was selected as the best answer
gv007gv007

I not have any proper techincal knowldge in chatter trying to get .But in yours case if you are getting an attachment from an external application ,you can downlaod it.if you explained more about yours problem that will helpful here.

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.

 

jhartjhart

Wow, a server-side screen scrape - nice hack!

LesKLesK

Yeah - you can do all sorts of things - send mail bulk mail, provisions things, re-write the public calendar, etc...

 

It is dangerous, but sometimes all you can do...