0

I'm getting a base64 String pdfContent from a callout response which I'm trying to save as a attachment of a record. I tried to save it after decoding it with

EncodingUtil.base64Decode('base64String'); - Didn't work

Tried to simply store it as Blob with

Blob.valueOf('base64String'); - Didn't work

The Blob is getting saved as attachment But When I try to view it, It throws an Error

"Failed to load Pdf Document"

How can I make it view-able?

Here's the apex logic of storing the attachment.

String base64String = 'some base64 String';
    Attachment atc = new Attachment();
    atc.Name = 'Test.pdf';
    atc.ContentType = 'application/pdf';
    //atc.Body = Blob.valueOf(base64String);
    //atc.Body = EncodingUtil.base64Decode(base64String);
    //atc.ParentId = 'a0041XXXXXXXXXX';
    insert atc;
2
  • 1
    EncodingUtil.base64Decode ... should work....may be input blob is faulty..
    – Ayub
    Commented Jun 27, 2018 at 7:20
  • Cheked the blob..It's missing some part.. Now EncodingUtil.base64Decode(); Worked
    – A.Bretto
    Commented Jun 27, 2018 at 15:03

1 Answer 1

1

Just adding as answer so that can help others:

Base64 input string was not complete and was causing faulty input blob.

After fixing it, EncodingUtil.base64Decode worked as expected.

You must log in to answer this question.

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