0

I am trying to upload Chatter profile photo from site. I have gone through the URL below, but still I am not getting the idea of how to achieve this. Please provide some code snippet or suggestions how to achieve this.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterUsers_static_methods.htm

final PageReference theUrll = new PageReference(SERVER_URL+'services/data/v30.0/connect/communities/0DB110000004CB‌​  EGA2/chatter/users/me/photo'); 
HttpRequest req = new HttpRequest(); 
req.setMethod('POST');   
req.setEndpoint(theUrll.getUrl());
req.setHeader('Authorization', 'OAuth ' +    UserInfo.getSessionId()); 
req.setHeader('cropSize', '120'); 
req.setHeader('cropX', '0');
req.setHeader('cropY', '0'); 
 req.setHeader('fileId', fileId); 
Http http = new Http(); HTTPResponse res = http.send(req);
  • 1
    Can you please provide some code that you've tried so far? – Boris Bachovski Jun 4 '14 at 5:26
  • final PageReference theUrll = new PageReference(SERVER_URL+'services/data/v30.0/connect/communities/0DB110000004CBEGA2/chatter/users/me/photo'); HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setEndpoint(theUrll.getUrl()); req.setHeader('Authorization', '120'); req.setHeader('cropSize', 'OAuth ' + UserInfo.getSessionId()); req.setHeader('cropX', '0'); req.setHeader('cropY', '0'); req.setHeader('fileId', fileId); Http http = new Http(); HTTPResponse res = http.send(req); – Arabinda Jun 4 '14 at 5:31
  • You've mixed up the headers in your http request, Authorization should have oAuth SessionID, and cropSize should be 120. – Boris Bachovski Jun 4 '14 at 5:35
  • But its throwing some exception [{"message":"The Chatter Connect API is not enabled for this organization or user type.","errorCode":"API_DISABLED_FOR_ORG"}].The way I am trying may be wrong.So I want to use connect API by following the above URL.If you can provide some code how to use connect API static method to upload an image in binary format , it will be really helpfull. – Arabinda Jun 4 '14 at 5:36
  • Sorry that was a type mistake. – Arabinda Jun 4 '14 at 5:37
3

check the below code.It may help you.
ConnectApi.BinaryInput fileUpload = new ConnectApi.BinaryInput(fileAsBlob, 'image/jpg', 'profileImage');
ConnectApi.Photo photoProfile = ConnectApi.ChatterUsers.setPhoto(communityId,userId,fileUpload);

|improve this answer|||||

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.