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?

  • This might help developer.force.com/cookbook/recipe/… – techtrekker Dec 7 '12 at 22:01
  • That's not really what I'm after. I'm looking for the HTTP POST data (similar to above), but modified for a User Photo POST. I'm trying to put together the POST data in C# to send the it using an HttpWebRequest. – Matt K Dec 7 '12 at 22:20

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 https://cs7.salesforce.com/services/data/v26.0/chatter/users/[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].salesforce.com
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

  • I tried, but got the following error: HTTP/1.1 400 Bad Request Date: Fri, 03 Apr 2015 17:06:53 GMT Set-Cookie: BrowserId=uTEL08HzRNCqIa--H-5oeA;Path=/;Domain=.salesforce.com;Expires=Tue, 02-Jun-2015 17:06:53 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 120 [{"errorCode":"INVALID_INPUT_COMBINATION","message":"Binary data expected because existing content was not specified."}] – PerlDev Apr 3 '15 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.