[SalesForce] Preview Chatter File in Visualforce

I've found a lot of people talking about this but no real answers. What I am trying to do is simple just show a little thumbnail preview of a file in a custom component

SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :selectedId

and then i though i could do something like

 <img src="/services/data/v28.0/chatter/files/{!file.ContentDocumentId}/rendition?type=THUMB120BY90" alt="Click to preview" class="contentThumbnail" title="Click to preview" id="ext-gen7"/>

but thats not working?

I also tried going from the Feed itself

public Resume__Feed getApprovedPost() {
        return [Select Id, Type, Title, Body, ContentData, ContentFileName from Resume__Feed where ParentID = :selectedId and Type = 'ContentPost'  ORDER BY CreatedDate DESC, Id DESC limit 1];
}

but wasnt able to get any of that to display?

My ideal is to display using their little flash file previewer but i'd settle for just getting the thumbnail?

any ideas?

Best Answer

This will work:

SELECT ContentDocument.LatestPublishedVersionId 
FROM ContentDocumentLink 
WHERE LinkedEntityId = :selectedId

then

<img src="/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId={!file.ContentDocument.LatestPublishedVersionId}" 
    alt="Click to preview" class="contentThumbnail" 
    title="Click to preview" 
    id="ext-gen7"/>

To download the actual content, the URL is

/sfc/servlet.shepherd/version/download/{!file.ContentDocument.LatestPublishedVersionId}
Related Topic