Upload Files To Microsoft Azure Blob Storage using Quarkus

Kenneth Kogi
4 min readDec 5, 2022

--

Hello there 👋, Its Kogi 😊

Cloud computing is currently becoming the norm for the creation of all software. Every step of the programming process, whether posting our code to GitHub or Gitlab, using Google Drive or Dropbox, or uploading our personal data, was done in the cloud.
In this tutorial, we’ll learn how to use Quarkus and Kotlin to implement file upload to Azure Blob.

Lets Begin, So whats Azure Blob Storage?

Blob storage is a feature in Microsoft Azure that lets developers store unstructured data in Microsoft’s cloud platform.Blobs are grouped into “containers” that are tied to user accounts. Blobs can be manipulated by using any programing language. Blob storage is designed for :

  • Serving images or documents directly to a browser.
  • Storing files for distributed access.
  • Streaming video and audio.
  • Writing to log files.
  • Storing data for backup and restore, disaster recovery, and archiving.
  • Storing data for analysis by an on-premises or Azure-hosted service.

Blob Storage is widely been used by the industry today for developing great user-friendly apps. Its best known for storing files, images and binary data. Today we are going to implement the Azure Blob using Quarkus and kotlin.

That’s a lot, Time to get our hands dirty.

Prerequisites

The following prerequisites are required in order to follow the steps in this article:

Step 1: generate Quarkus Project?

Bootstrap a new quarkus project from Quarkus Initializer

https://code.quarkus.io/

Step 2: Install the azure dependencies

    implementation("com.azure:azure-storage-blob:12.19.1")
implementation("com.azure:azure-identity:1.6.1")

Step 3: Configuration from Azure

  1. Blob Container Name
  2. Account Key — Secret Key
  3. Blob Container Endpoint

Configure the azure credentials in application properties

Step 4: Create a controller endpoint for creating and reading a file

Step 5: File Upload Service

Initialize azure configs from the application properties in your service

Inside the upload file function, declare a connection URL variable of concatenated azure account name and account key.

Establish a connection to Azure Store through BlobContainerClientBuilder class. This class provides a fluent builder API to help aid the configuration and instantiation of BlobContainerClient and BlobContainerAsyncClient, call buildClient() and buildAsyncClient() respectively to construct an instance of the desired client.

Read the file data from the source using InputStream. Then through getBlobAsyncClient class initialize a client that contains generic blob operations for Azure Storage Blobs. Operations allowed by the client are uploading and downloading, copying a blob, retrieving and setting metadata, retrieving and setting HTTP headers, and deleting and un-deleting a blob.

Finally, upload the file asynchronously.

Step 5: Read File Service

Establish a connection to Azure Store through BlobContainerClientBuilder class. Configure shared access signature parameters(SAS).

Finally, generate a signed URL using the container client.

I hope this learning process-like article has helped your understanding of uploading files to azure blob storage. Thanks for reading and please give me a like or comment if there is something incorrectly written or it can be improved in any way!

Here is the link to the GitHub Repository.

References

[1] Upload to Azure Blob Storage

[2] Getting started with Quarkus

--

--