How to copy a file from one Azure container to another using VS Code in Business Central ?

Introduction:

This blog demonstrates how copy a file from one azure container to another container placed in the same storage location using VS Code in Business Central.

Pre-requisites:

  1. Visual Studio Code (VS Code)
  2. Business Central SaaS environment
  3. Files uploaded to one container

Steps:

We need a basic setup in Business Central where we define the blob storage name , the source container and the destination container with the access key.

  1. Go to your Microsoft Azure account, open your storage account and copy your access key

2. Create two Containers, source and destination. In my example test1 is the source

3. Change the public access level on both source & destination containers to Container (anonymous read access for container and blobs)

4. Create a setup table in Business Central to enter the storage account, source and destination containers with the access key like below.

5. Creating an action button on the setup page to trigger the custom codeunit.

6. We’ll be using Azure blog storage in business central to copy blob files from source to destination containers. Following standard objects will be used

6. Storage Service Authorization codeunit is used for the authentication and Azure Blob client is used for uploading and reading files in your Blob Storage.

7. In the below code snapshot, we are storing the shared access key in an Interface Storage service Authorization and initializing the Azure Blob client to read the source and destination container

8. Get a List of blobs from ABS Container Container Content and create a loop to get the blob from the source container as stream and use PutBlobBlockBlobStream function of the destination blob client to copy the stream file to the destination.

9. Final step is to publish the file.

10. Upload a file to the source container

10. Navigate to the setup page and run the job to copy file to the destination.

11. File is Copied to the destination container.

Happy Friday!!

2 thoughts on “How to copy a file from one Azure container to another using VS Code in Business Central ?

Leave a comment