function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maros SitkoMaros Sitko 

chatter rest api - send attachment

Hi, can you help me with post Chatter feed item with REST API?
I am able to post feeditem with attachment, but after download attachment (image),
my computer say that it is broken. So I thing, I have wrong Content-Type.
Here is my JSON

Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8

{"body":{"messageSegments":[{"type":"text","text":" From CassaDeveloper:\nabc"}]},"attachment":{"attachmentType":"NewFile","title":"image.png"}}


 Content-Disposition: form-data; name="feedItemFileUpload"; filename="image.png"
Content-Type: application/octet-stream; Content-Transfer-Encoding: base64

blob of content which is from ContentVersion EncodingUtil.base64Encode((blob)file[0].VersionData)

 I build it with apex as a String:

list<ContentVersion> file = [SELECT id, Title, VersionData, PathOnClient FROM ContentVersion where id = :attId];
jsonBody = '--0HW....';
jsonBody += EncodingUtil.base64Encode((blob)file[0].VersionData);
jsonBody += '--0H';
request.setHeader('Content-Type',  'multipart/form-data; boundary=0HWq8x4y4DSQ4fqjXt6MinVMyqbf1r');

  Thank you

Hi Marco,

Could you please try keeping Content-Transfer-Encoding: binary instead of base64.

I found this code when reasearchng and seems this works: