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);
9
  • 1
    Can you please provide some code that you've tried so far? Jun 4, 2014 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, 2014 at 5:31
  • You've mixed up the headers in your http request, Authorization should have oAuth SessionID, and cropSize should be 120. Jun 4, 2014 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, 2014 at 5:36
  • Sorry that was a type mistake.
    – Arabinda
    Jun 4, 2014 at 5:37

1 Answer 1

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);

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .