I have byte array data of user image and what is best way to upload contact/lead profile photo and what is the REST API for uploading the same.

I have also social site photo url. is there any API to upload using photo url as profile image?

  • You wanna upload this to docs or attachments? Sep 8, 2015 at 14:45

1 Answer 1


You can upload image to salesforce by making a http callout to the URL and get the image as response and save it to the documents object. First create a folder in documents tab and save the images.

start up code that can help you.

public class ImageUpload{
public Static void ImageUploadVAttachment(){
Http h = new Http();
HttpRequest req = new HttpRequest();
string firstImageURL =  'Endpoint URL should go here';
firstImageURL = firstImageURL.replace(' ', '%20');
req.setHeader('Content-Type', 'image/jpg');
HttpResponse res = null;
res = h.send(req);
//These next three lines can show you the actual response for dealing with error situations
string responseValue = '';
responseValue = res.getBody();
system.debug('Response Body for File: ' + responseValue);
// getBodyAsBlob method 
blob image = res.getBodyAsBlob();
//Not that by simply inserting into ContentVersion that the actual   ContentDocument entry will be created for you
ContentVersion cv = new ContentVersion();
cv.VersionData = image;  //This is our blob
cv.title = 'MyImageName';
cv.Description = 'MyImageDescription';
cv.FirstPublishLocationId = '058q00000000Y6B';  //This is the library
cv.TagCsv = 'Tag1';
cv.PathOnClient = '';
cv.ReasonForChange = ''; // If we update an image then we may have to set this
//cv.ContentDocumentID = ''; //If we are inserting a revision to a document then we need this.  May have to query for it first
//When testing this remember that it takes a few seconds for a document to show up in the library
 insert cv;

You must log in to answer this question.

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