Newer Version Available
Post a Feed Element with a New File (Binary) Attachment
This example calls the postFeedElement(communityId, feedElement, feedElementFileUpload) method to post a feed item with a new file
(binary) attachment.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
18input.subjectId = 'me';
19
20ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
21contentInput.title = 'Title';
22
23ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
24capabilities.content = contentInput;
25
26input.capabilities = capabilities;
27
28String text = 'These are the contents of the new file.';
29Blob myBlob = Blob.valueOf(text);
30ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'text/plain', 'fileName');
31
32ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input, binInput);