How to convert Base64 to Image in apex?

ContentVersion co = [Select id,pathOnClient,title,versionData  from ContentVersion ];

Co.versiondata has base 64 data , i need to convert this to Image format.

can anyone help me how can i achieve this?

Thanks, Mahesh

2 Answers 2


In Apex, the ContentVersion.VersionData data type is already a Blob, which is a special way Salesforce represents and passes around binary data.

You may obtain String version of the data using Blob toString() method or EncodingUtil.base64Encode( Blob ) method.




You need to transform that into Blob

ContentVersion co = [Select id,pathOnClient,title,versionData  from ContentVersion ];

Blob image = EncodingUtil.base64Decode(Co.versiondata);
  • Method does not exist or incorrect signature: void base64Decode(Blob) from the type System.EncodingUtil.
    – Mahesh
    Jun 4, 2017 at 5:46
  • i am getting the above error , when i am trying to execute the code.
    – Mahesh
    Jun 4, 2017 at 5:47
  • versiondata is itself a blob type!!
    – Ayub
    Mar 4, 2022 at 9:12

You must log in to answer this question.

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