Post a Feed Element with a New File (Binary) Attachment
Call a method to post a feed element with a new file.
postFeedElement(communityId, feedElement,
feedElementFileUpload) to post a feed item
with a new file (binary)
attachment.
This example calls ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.subjectId = 'me';
ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
contentInput.title = 'Title';
ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
capabilities.content = contentInput;
input.capabilities = capabilities;
String text = 'These are the contents of the new file.';
Blob myBlob = Blob.valueOf(text);
ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input, binInput);