web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

pdf download from blob storage - not valid pdf file

(0) ShareShare
ReportReport
Posted on by 58

Hello

I just to tried to make the Saas File Management exercice from a BC book

Uploading a pdf file works fine

Downloading produces a file that is not valid - cannot be opened bye a pdf reader

I have the impression that the base64 variable does not change (in the debugging watch) when executing the base64Convert.FromBase64 function : 

...
httpResponse
.Content.ReadAs(base64);
base64 := DelChr(base64, '=''"');
base64Convert.FromBase64(base64);
tempblob.CreateOutStream(outstr);
...
When charging the file in an editor I see something beinning like this : 
JVBERi0xLjcNCiWhs8XXDQoxIDAgb2JqDQo8P ...

When modifying AL (the conversion part) and the related c# code to return the file content directly (no base 64) I get something more ressembling to a pdf file : 
%PDF-1.7 ...
but even this one is not valid

Does anybody have any idea what I'm doing wrong ?
I have the same question (0)
  • JAngle Profile Picture
    133 on at

    I’ve encountered a similar challenge. I’ve added this question on Twitter and used [tag:bcalhelp] as it is well tracked. Hopefully an answer follows on

  • Suggested answer
    ajkauffmann Profile Picture
    117 on at

    Don't remove the = at the end of the string. Base64 works with groups of 4 characters. The = is added as a padding at the end to ensure that the last group is also 4 characters.

    What is also going wrong is the call to Base64Convert. The purpose of the call is to return the original value.

    First of all you must catch the return value, like:

    MyText := Base64Convert.FromBase64(Base64Text)

    But in this case the result will not be text, it will be binary. So you should use the OutStream.

    In full, the code should be as follows:

    HttpResponse.Content.ReadAs(base64);
    TempBlob.CreateOutStream(outstr);
    Base64Convert.FromBase64(base64, outstr);

  • Verified answer
    gtr2 Profile Picture
    58 on at

    Thanks - works fine now :)

  • Verified answer
    Marco Mels Profile Picture
    on at

    Thank you Arend-Jan, I will ask the team to publish this on our CSS Twitter account to get more traction.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans