Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Converting a Rich Text Area Field's Image for API Upload

Converting a Rich Text Area Field's Image for API Upload

Post by API Doc'er  (2011-06-17)

Status: Unverified
Level: intermediate

Uploading Images Using the API

If records include rich text area fields containing images, you must convert the image to Base64 and supply that as the value in the relevant field. You can use a text editor to do this.


  1. Encode the desired image into Base64.
  2. Copy the entire Base64 image string to the clipboard.
  3. Copy the following text and paste it into a text editor:
    <img alt="<image_Name>" src="data:image/<image_File_Extension>;base64, <base64_Image_String>"></img>
    • Replace <image_Name> with the file name of the image. Don’t include the file extension. For example: Headshot1
    • Replace <image_File_Extension> with the extension of the image file. Don’t include the dot. For example: jpg
    • Replace <base64_Image_String> with the string that you copied in Step 2.
  4. Copy the entire source text data and use it as the value in the relevant field of the API.
  5. Upload the data.


Recipe Activity - Please Log in to write a comment

I think an image conversion control may be helpful. When using the image conversion SDK to convert image, image format and its color space and depth are detected automatically. Meanwhile, image conversion is often finished at high speed without quality loss.

by a093000000Xxuuj  (2013-12-06)

Hey it worked well by removing space but after saving into server may i knwo how to rxtract the data back ?

by a093000000XZ1hO  (2013-08-30)

I just wanted to point out a possible error based on the code above. There is a space between ";base64," and "<base64_Image_String>". I believe it is just a typo but having that space there caused an error, removing it did the job. Just something to look out for.

by a093000000WcQtt  (2013-03-20)

Dear Sir,

We are building an iOS app that needs to download and display images from a custom Rich Text field in the User object.

We are following your approach, the problem we face is within "step 1": Encode the desired image into Base64.

This is when we "grab" the image itself from its URL contained in the rich-text area. When we perform the request for the image itself we are blocked by an authorization/access rights problem even though the session is already authorized.

Thanks for any help you can give!

by Niels Christensen  (2012-09-03)

Hey i want to upload an image into custom database object. 

For that i use jason object to put data into custom object and i also convert the image in to Base64 and then put data on to custom object.
I have successfully upload that data into custom object but when i open the image it not showing into editor, it still take image as a text data. 

So i don't no what's the problem , if you have any idea or some simple code snippet for how to upload image from andorid client then please share with me.


by Jalp Bhatt  (2012-03-12)

I am developing Android application in which i have integrated salesforce stuff using REST API. I want to upload base64 image data from Android client to and rigth now i am getting following error:

As per current implementation i am getting error message: Invalid encoding specified:  base64. The base64 is the only supported encoding.","errorCode":"INVALID_DATA_URI"


Any help/pointer on this would be gretly appriciated - thank you.

by maayank.tiwari03112012  (2012-03-12)


Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.