+ Start a Discussion

Chatter File Uploads

What's the best way to upload a file to a chatter post in a custom interface in a visualforce page. Yes I know there is a visualforce component that provides all the chatter functionality, but let's say you don't want to use the component. How would you upload a chatter file with javascript remoting? 





Use Chatter in Apex, which is a set of classes in the ConnectApi namespace that expose much of the Chatter REST API functionality in Apex. 


Call ConnectApi.ChatterFeeds.postFeedItem(String, ConnectApi.FeedType, String, ConnectApi.FeedItemInput, ConnectApi.BinaryInput)


The docs have sample code for uploading an attachment to a comment (scroll to the end of the page). You can edit the code to upload an attachment to a post. 




Hope that helps,