Using Wisej to access Blob Storage with Microsoft Azure | fecher's Developer Blog
Wisej and Azure Blob Storage
Using Wisej to access Blob Storage with Microsoft Azure

Using Wisej to access Blob Storage with Microsoft Azure

During a Web Enabling process, one of our standard tasks that we analyze with our customers refers to file management. Our experience has proven that the desktop applications heavily used file manipulation, therefore we need to provide modern options to support this feature also for the web-enabled applications.

The Wisej Framework is very flexible and extensible when it comes to file handling. It provides an abstract interface for file access enabling you to use any file system that your .NET web applications need: either the built-in default implementation for the standard disk-based file system or several alternative implementations for cloud-based file storage.

Nowadays it is extremely attractive to entirely deploy the web application as SaaS on Microsoft Azure environment. Therefore, the solution offered by Azure platform goes for Microsoft Azure Files that can be used to completely replace or supplement traditional on-premises file servers.

In this article, I am describing the way a Wisej web application can interact with cloud files stored on Microsoft Azure Blob Storage. Connecting your web application to Azure Blob Storage requires just a few simple steps.

How to use Azure Blob Storage with Wisej

Prerequisites:

  • Azure subscription
  • Azure storage account
  • Reference Wisej 2.5

Install Azure.Storage.Blobs 12.10 library in your solution:

Install System.Runtime.CompilerServices.Unsafe version 4.6.0:

The Compiler Services will require a binding redirect in the Web.config file:

Install System.Buffers version 4.5.1:

The System.Buffers will require a binding redirect in the Web.config file:

The implementation of AzureBlobProvider

The file system implementation for the Azure Blob storage needs to be placed in a class that implements the Wisej “IFileSystemProvider”, I named my new class “AzureBlobProvider”:

The authentication to the Blob storage can be done in many ways like the Microsoft documentation indicates – the actual authentication is not in the current scope of this article, but rather the file access part is more relevant. Independent of the authentication type, for the actual Azure Blob storage connection, we need to know the account & container name – which is stored in our “AzureBlobProvider” class members:

Scenario 1: Import Operation

For a standard import operation, the end user should be able to select the file path from the Azure storage. To achieve the file import, I have used a Wisej Open File Dialog where I added both a local folder and an Azure Blob storage container just to show case that both file systems can be used together:

If we run the sample, the user is prompted with a file picker dialog – as shown, the Azure Blob Storage folder structure is displayed:

This is possible because the Wisej Open File Dialog calls “GetDirectories” and “GetFiles” methods from our “AzureBlobProvider” class: 

For displaying the file properties, the “AzureBlobProvider” class implements methods like: “GetFileSize” or “GetCreationTime”.

After the user selects the imported file, the web application may require processing the file content. On the server side, this operation means downloading the Azure Blob item and reading its content.

The implementation for downloading and reading a Blob item’s content is here:

Scenario 2: Export operation

Another common scenario is when the web application is generating a report which should be uploaded to either a pre-defined or a user-defined Azure location. To simulate the export, in my sample, you can type in the file content and then click the Upload button:

After clicking the Upload button, the Save File Dialog allows you to specify the location and the name of your file:

The result will be uploaded in Azure Storage:

Wisej is a very powerful web application framework which enables taking advantages of latest .NET technologies.
For further examples on how to implement cloud storage file access, I recommend the Amazon S3 file system implementation provided by the Ice Tea Group, which was also my support for developing the Azure Storage file system provider.

wisej-extensions/Wisej.FileSystem.AmazonS3 at 2.5 · iceteagroup/wisej-extensions (github.com)

Here you can download a file on that topic which contains the AzureBlobProvider class and a sample where this is used. It’s a showcase of folder browsing through Azure Blob items and demonstrates uploading/downloading a file to Azure Blob storage.