0

I am trying to understand if I can upload a user profile picture in Salesforce using Rest.

I have performed the following :

Uploaded a file in Salesforce. Then I used the file Id to upload it into the user profile picture

{   "cropSize" : "240",
    "cropX" : "20",
    "cropY" : "20",
    "fileId" : "0696F000005C4NB"
}

I tested the above using workbench, Which works successfully. But it requires the file to be uploaded in file object before.

I would like to understand if

  1. I can also upload the picture in file object using rest.
  2. Is so then what would be its JSON format.
  3. Also can I test the above using workbench or any other API tool.
1

Inputs and Binary File Uploads shows you how this works:

POST /services/data/v42.0/chatter/users/me/photo HTTP/1.1
Authorization: OAuth 00DD0000000Jhd2!AQIAQC.lh4qTQcBhOPm4TZom5IaOOZLVPVK4wI_rPYJvmE8r2VW8XA.
OZ7S29JEM_7Ctq1lst2dzoV.owisJc0KacUbDxyae
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: ***instance_name***
Content-Length: 543
Content-Type: multipart/form-data; boundary=a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Accept: application/json

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Type: application/json; charset=UTF-8
Content-Disposition: form-data; name="json"

{
   "cropX" : "0",
   "cropY" : "0",
   "cropSize" : "200"
}

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="fileUpload"; filename="myPhoto.jpg"
Content-Type: application/octet-stream; charset=ISO-8859-1

...contents of myPhoto.jpg...

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq--

It's a normal multipart/form-data upload mechanism. However, since you need to upload binary data, you will likely be unable to directly use Workbench to accomplish this task.

You can use something like CURL, as also mentioned in the documentation:

curl -H "X-PrettyPrint: 1" -F 'json={"cropX": "0", "cropY": "0", "cropSize": "200"};type=application/json'
 -F "fileUpload=@myPhoto.jpg;type=application/octet-stream" 
-X POST https://***instance_name***/services/data/v42.0/chatter/users/me/photo
 -H 'Authorization: OAuth 00DRR0000000N0g!ARoAQFRi_gBqZhajAX22MNuLrrE2Xk...'
 --insecure
  • is there any documentation to perform the above using postman? @sfdcfox – user55791 Apr 22 '18 at 14:00

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.