0

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

0

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.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_blob.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm#apex_classes_restful_encodingutil

0
0

You need to transform that into Blob

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

Blob image = EncodingUtil.base64Decode(Co.versiondata);
3
  • Method does not exist or incorrect signature: void base64Decode(Blob) from the type System.EncodingUtil.
    – Mahesh
    Commented Jun 4, 2017 at 5:46
  • i am getting the above error , when i am trying to execute the code.
    – Mahesh
    Commented Jun 4, 2017 at 5:47
  • versiondata is itself a blob type!!
    – Ayub
    Commented 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 .