Newer Version Available
Post a Feed Element with a New File (Binary) Attachment
Call a method to post a feed element with a new file.
This example calls postFeedElement(communityId, feedElement,
feedElementFileUpload) to post a feed item
with a new file (binary)
attachment.
1ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
2input.subjectId = 'me';
3
4ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
5contentInput.title = 'Title';
6
7ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
8capabilities.content = contentInput;
9
10input.capabilities = capabilities;
11
12String text = 'These are the contents of the new file.';
13Blob myBlob = Blob.valueOf(text);
14ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
15
16ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input, binInput);