Find your content:

Search form

You are here

Chatter REST Api User Photo Example


I'm looking for an example that uses the Chatter REST Api to upload a User Photo.

The documentation explains the syntax, but they don't give an example of the HTTP form data to POST.

Elsewhere in the documentation, an example is given for posting a file, though:

POST /services/data/v26.0/chatter/feeds/user-profile/005x0000001TBMVAA4/feed-items HTTP/1.1
Authorization: Bearer 00Dx00000001hQY!ARUAQPg.NZBUVAWJh8Dd8UtWHE2k1o0wQuyN9XcRjqZNnuiGJ_YdaQ5uqGa.j7iK4VKF6jzsP3PBvDlQyJ8.MKI983iDUC78
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: instance_name
Content-Length: 897
Content-Type: multipart/form-data; boundary=0HWq8x4y4DSQ4fqjXt6MinVMyqbf1r
Content-Disposition: form-data; name="xml"
Content-Type: application/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit

            <text>High priority content </text>
            <text>Please review this as soon as possible</text>
      <desc>Quarterly review</desc>
Content-Disposition: form-data; name="feedItemFileUpload"; title="2012_q1_review.ppt"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary

binary stream of file


How would the example above be modified to upload a User Photo?

Attribution to: Matt K

Possible Suggestion/Solution #1

Here's the POST data that ended up working for me. I had to use JSON instead of XML in the first part of the POST (after the first boundary) because XML was returning an UNKNOWN EXCEPTION. I'm sure there's a way to use XML, though; I just don't know how.

POST[my-user-id]/photo HTTP/1.1
Accept: application/xml
Content-Type: multipart/form-data; boundary=8cfa66b1737e032
Authorization: OAuth [my-session-id]
Host: [my-Salesforce-instance-name]
Content-Length: 32075
Expect: 100-continue

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

Content-Disposition: form-data; name="fileUpload"; filename="photo.jpg"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary


Attribution to: Matt K
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content