Easiest way to download file from URL in Business Central SaaS

Have you ever tried to make NAV or BC download a file using an URL? How many different ways have you done it already? Let’s try to find a quick one here.

So here I was trying some stuff with file management and file downloads from other sources in BC SaaS (also compatible with OnPremise), more to come in the future, and stumbled upon a new feature Microsoft provided us with that I loved. So easy and quick.

One of the steps I need was downloading a file from an URL, and when I had all my http-like variables set up and working I found a very special new function.

TempBlob table has new functions, among them the “TryDownloadFromURL”. This can easily help in our mission to download a file from an URL.

So if it works as I expect it to, it should be super easy. Let’s try put it to the test:

trigger OnAction()
                var
                    TempBlob: Record TempBlob temporary;
                    IStream: InStream;
                    FileName: Text;
                begin
                    clear(TempBlob);
                    TempBlob.Blob.CreateInStream(IStream);
                    FileName := 'microsoft.jpg';
                    TempBlob.TryDownloadFromUrl('https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31');
                    DownloadFromStream(IStream, 'Download File', '', '*.*', FileName);
                end;

So it does download the file from the URL and save it in the TempBlob.Blob field. And you can use it from there however you want! That’s neat.

If we try it we get the following:

Do you know an easier way to do this or have any questions? Let me know below!

Want to learn more about BC? You can check the blog!

Leave a Reply

Your email address will not be published. Required fields are marked *