0

This has been bugging me for a while. I think I am missing something very obvious.

So from a REST api I am getting a base64 data of a PDF. I am trying to save the PDF as Attachment under an object. I am trying:

attach.Body = EncodingUtil.base64Decode(myBase64DataString);

it gets saved but while opening the PDF I get -

Failed to load PDF.

I have been trying various blogs and old SFSE questions but could not figure out what am I doing wrong.

Facts:

  1. myBase64DataString is holding correct base64 data as when I do data:application/pdf;base64,<myBase64DataString> in address bar of browser, its loading the PDF.
  2. When I attach any other valid PDF using Attach File button of Notes & Attachment related list, I see no difference between the attachment records created by apex and uploading the file using Attach File button.

Please point me to the right direction.

Update 1: On request from Eric, posting the base64 data string, if that helps.

JVBERi0xLjQKJeLjz9MKNCAwIG9iajw8L1hPYmplY3Q8PC9JbTEgNSAwIFI+Pi9Qcm9jU2V0Wy9QREYvSW1hZ2VDL1RleHRdL0ZvbnQ8PC9GMSA2IDAgUi9GMyA3IDAgUi9GMTEgOCAwIFI+Pj4+CmVuZG9iagozIDAgb2JqIDw8L0xlbmd0aCAzNTgzL0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicxVttc6M2Hn+fT+HZvrhsp8YSiKd9c0Ns3HXrhxQ7e91ebm6IQxLP2ibFzm7z7SshQH+BAKWdm+tOJ8b+of/zkxBXm4twc/H7BUaegQbsH0aWYQ9M26TXjm3Y3mB7uBjNDngwSS9+ubjaXIymeMDQm4cLxP5sL9Dg8QLzuwfYdgwfD1z6h9jOYHMY/PtyEl4H0WYRLjfvB0PTZTdfrqbi88fVIpwHy4n4Zh2Ob6LZ5vP7wX8Gm59ykhhxmhUhYhm+P3CJbXgmpzNN7pMs3otlwkOSPSbH7av4ahEf48fkkBzP4rugwBS0rAYtzzFMxx64FjFsl9NabyjDQQR4ns5XK3D5MfhN+nkSbsJoMVsGm9lqCe5aRQtxdXu5nn6cTG/fA8E9mRfimoZjklxwExUaXi2uxCLj9HjOUqCGZWqIC+w4aIgQQQWJcl0bY8MldF3LEeuGfzzvsuT0AdyORhYeYa+4O/ceZn96Fxq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Rm9udC9IZWx2ZXRpY2EtQm9sZC9UeXBlL0ZvbnQvRW5jb2RpbmcvV2luQW5zaUVuY29kaW5nL1N1YnR5cGUvVHlwZTEvTmFtZS9GMz4+CmVuZG9iagoyIDAgb2JqPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbMSAwIFJdPj4KZW5kb2JqCjkgMCBvYmo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFI+PgplbmRvYmoKMTAgMCBvYmo8PC9Qcm9kdWNlcihpVGV4dDEuMy4xIGJ5IGxvd2FnaWUuY29tIFwoYmFzZWQgb24gaXRleHQtcGF1bG8tMTU0XCkpL01vZERhdGUoRDoyMDE3MDYyMjE0MTkyNi0wNicwMCcpL0NyZWF0aW9uRGF0ZShEOjIwMTcwNjIyMTQxOTI2LTA2JzAwJyk+PgplbmRvYmoKeHJlZgowIDExCjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwOTIwNCAwMDAwMCBuIAowMDAwMDA5NTkzIDAwMDAwIG4gCjAwMDAwMDAxMTkgMDAwMDAgbiAKMDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAzNzcwIDAwMDAwIG4gCjAwMDAwMDkzOTggMDAwMDAgbiAKMDAwMDAwOTQ5MyAwMDAwMCBuIAowMDAwMDA5Mjk5IDAwMDAwIG4gCjAwMDAwMDk2NDMgMDAwMDAgbiAKMDAwMDAwOTY4NyAwMDAwMCBuIAp0cmFpbGVyCjw8L1Jvb3QgOSAwIFIvSUQgWzw1MTk5ZTA2MmRlZjQ3ZThhMzEyZDVlNWMyOWMzN2YyMD48NTE5OWUwNjJkZWY0N2U4YTMxMmQ1ZTVjMjljMzdmMjA+XS9JbmZvIDEwIDAgUi9TaXplIDExPj4Kc3RhcnR4cmVmCjk4NDMKJSVFT0YK

Update 2: I am running the below snippet in anonymous window.

String base64 = '....';//my base 64 data
Blob myBlob = Blob.valueOf(base64); //Its converting it to a blob
System.debug(myBlob); //prints Blob[13616]
System.debug(myBlob.toString()); //Reverting it back to base 64 data
System.debug(EncodingUtil.base64Decode(base64)); //prints Blob[10212]
System.debug(EncodingUtil.base64Decode(base64).toString()); //Error - System.StringException: BLOB is not a valid UTF-8 string

Please notice the Blobs created by Blob.valueOf and EncodingUtil.base64Decode() are of different sizes.

4
  • 1
    Did you try just blob.valueOf instead of the decode? Just a shot in the dark. Can you post the data string?
    – Eric
    Jun 22, 2017 at 21:07
  • Yes, I tried blob.valueOf too, still same. Jun 23, 2017 at 16:17
  • Added the base64 string in the question. Jun 23, 2017 at 16:20
  • 1
    Thanks for the string. See answer for reproducible example using your string
    – Eric
    Jun 23, 2017 at 17:22

2 Answers 2

5

Did you set the contentType as application/pdf? I tried this following code and it is working for me.

String jsonStr = '<Base64 String>';
Attachment attach = new Attachment();
attach.contentType = 'application/pdf';
attach.name = 'myfile.pdf';
attach.parentId = '0010H00002DW2Ds';
attach.body = EncodingUtil.base64Decode(jsonStr);
insert attach;
4
  • Yes I tried that as well. Still failed to load pdf. I see no difference in attributes between 2 attachments uploaded from standard attach File button and inserted through apex. Jun 23, 2017 at 16:08
  • Updated the question with few other info, please check if those can help. Jun 23, 2017 at 16:39
  • 1
    I used your Base64 string in my above code and it is working for me. I tested the pdf in Chrome, Firefox and Adobe reader.
    – Saroj Bera
    Jun 23, 2017 at 18:15
  • It was not at all an issue related to base64, blob or decoding. An else phrase was missing and cost me a whole day :(. Thanks for your time Saroj. :) Jun 23, 2017 at 18:32
1

Code is same as the other answer, this answer serves to show proof / reproducible example, that doing it as suggested will produce a PDF file that can be viewed. If it is not working for you then there may be something else going on? This worked fine for me in exec anon attaching to an account then viewing it:

String t = 'JVBERi0xLjQKJeLjz9MKNCAwIG9iajw8L1hPYmplY3Q8PC9JbTEgNSAwIFI+Pi9Qcm9jU2V0Wy9QREYvSW1hZ2VDL1RleHRdL0ZvbnQ8PC9GMSA2IDAgUi9GMyA3IDAgUi9GMTEgOCAwIFI+Pj4+CmVuZG9iagozIDAgb2JqIDw8L0xl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owMDAwMDA5NTkzIDAwMDAwIG4gCjAwMDAwMDAxMTkgMDAwMDAgbiAKMDAwMDAwMDAxNSAwMDAwMCBuIAowMDAwMDAzNzcwIDAwMDAwIG4gCjAwMDAwMDkzOTggMDAwMDAgbiAKMDAwMDAwOTQ5MyAwMDAwMCBuIAowMDAwMDA5Mjk5IDAwMDAwIG4gCjAwMDAwMDk2NDMgMDAwMDAgbiAKMDAwMDAwOTY4NyAwMDAwMCBuIAp0cmFpbGVyCjw8L1Jvb3QgOSAwIFIvSUQgWzw1MTk5ZTA2MmRlZjQ3ZThhMzEyZDVlNWMyOWMzN2YyMD48NTE5OWUwNjJkZWY0N2U4YTMxMmQ1ZTVjMjljMzdmMjA+XS9JbmZvIDEwIDAgUi9TaXplIDExPj4Kc3RhcnR4cmVmCjk4NDMKJSVFT0YK';

Attachment a = new Attachment(ParentId={IDHERE});

a.body = EncodingUtil.base64Decode(t);
a.Name = 'Test.pdf';
insert a;

enter image description here

2
  • I should just kill myself! There was so much of code in the class that I missed to notice that an if-else block is missing the phrase 'else', so it was just if(){att.body=good blob}{att.body = faulty blob;} due to which a faulty Blob was being set to att.body. :( Thank you so much for your time though, Eric. Jun 23, 2017 at 18:29
  • 1
    @SantanuHalder - Anytime. Thats why I posted this so you could get your focus elsewhere and know that the code you though was wrong was in fact correct :)
    – Eric
    Jun 23, 2017 at 20:40

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.