Last week I was writing that the functionality of “Attachments” in Business Central was storing the files in the database. And I’m not a fan of that. But Kennie pointed me to a new feature in Business Central 2021 wave 2. The Azure Blob Storage in the system app (more details about Azure Blob Storage you can find here: Introduction to Blob (object) storage – Azure Storage | Microsoft Docs).
Well exactly there are two modules of Azure Blob Storage. The first one is the “Azure Storage Service Authorization” this one is for the authentication. There are two types of authentication. The first is the “Shared Key” and the second is the “Shared Access Signature”. And it is very simple to authorize it through AL code:
On line 33 you can see that you must put the key in the interface “Storage Service Authorization” and that interface you need in the second module. The “Azure Blob Services API”.
In there there are two codeunits that are important “ABS Container Client” and “ABS Blob Client”. The first one is for creating / deleting containters. And the second one it for putting / reading files in your Blob Storage.
But when you want to use it you have to use the initialize function first in the codeunit. And there you have the variable authorization needed (in line 34).
So it is a very usefull function for a very quick implementation of Azure Blob Storage in Business Central. So lets make it work with the document attachment😊.
First you need to store the file into the Blob Storage when you select a file:
After that we want to delete the file in the media field:
And offcourse when you delete the line, the file on the Blob Storage must also be deleted:
And offcourse you must create an extra button that you download the file from the Blob Storage. Therefor you need to create a page extension on the page “Document Attachment Details”.
And if you publish it the files aren’t stored in your database anymore but on Azure Blob Storage 😊.
The source of this little feature you can find on my GitHub Bertverbeek4PS/AzureBlob (github.com) (this source is based on Business Central 2021 wave 2 – preview).
So enjoy the connection with Azure Blob Storage and Business Central 😊.