You need to sign in to do that
Don't have an account?

wanna update Profile Image by using CHATTER API after getting the Image from external Source using HTTP Response.
Hi ALL,
i have one requirement where should i call HttpRequest for Image and after getting the response i should take that image and set as that image as Current User profile image. mine is not communirty.
i have written below logic, but when i am checking documnet record attachment i am seeing blank image but having size.
please help me on this if i am doing anything wrong.
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(iosx.DownloadUrl__c);
req.setTimeout(60000);
req.setMethod('GET');
req.setHeader('Content-Type', 'image/jpg');
HttpResponse res = h.send(req);
Blob body = res.getBodyAsBlob();
if(body!=NULL){
Document document = new Document();
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId();
document.Body = body;
document.Name=iosx.Name__c;
document.contentType='image/jpg';
document.IsPublic = true;
insert document;
ConnectApi.BinaryInput photoFileInput = new ConnectApi.BinaryInput(body,'image/jpg',iosx.Name__c);
ConnectApi.photo profilepic=ConnectApi.UserProfiles.setPhoto(null,UserIdValue,photoFileInput);
i have one requirement where should i call HttpRequest for Image and after getting the response i should take that image and set as that image as Current User profile image. mine is not communirty.
i have written below logic, but when i am checking documnet record attachment i am seeing blank image but having size.
please help me on this if i am doing anything wrong.
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(iosx.DownloadUrl__c);
req.setTimeout(60000);
req.setMethod('GET');
req.setHeader('Content-Type', 'image/jpg');
HttpResponse res = h.send(req);
Blob body = res.getBodyAsBlob();
if(body!=NULL){
Document document = new Document();
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId();
document.Body = body;
document.Name=iosx.Name__c;
document.contentType='image/jpg';
document.IsPublic = true;
insert document;
ConnectApi.BinaryInput photoFileInput = new ConnectApi.BinaryInput(body,'image/jpg',iosx.Name__c);
ConnectApi.photo profilepic=ConnectApi.UserProfiles.setPhoto(null,UserIdValue,photoFileInput);