In this tutorial, we’ll use Azure Blob Storage for file operations through the NodeJS API endpoint, such as uploading and deleting files.
Azure Blob Storage
Azure Blob Storage is Microsoft’s cloud-based object storage solution. Blob storage can store a massive amount of unstructured file data.
Prerequisites
If you don’t have a Microsoft Azure subscription, you can get a free account before you begin. Once the account is set up, you will be given a couple of keys that you will need to work with:
- Blob Service Endpoint Url: http://youraccountname.table.core.windows.net/
- Storage Account Name: youraccountname
- Primary Access Key: lkdjwy87y34riuflkj1y38hufi3o7yhf8diu4e (something cryptic like that)
The following are the essential components for creating an Azure blob storage resource:
- Storage Account: A Storage account in Azure provides a unique namespace for all of the data we will save.
- Containers: Containers are similar to folders and store blobs.
- Blobs: Blobs are objects that can hold large amounts of text or binary data, including images, documents, streaming media, and archive data.
Now create a container and set up the environment according to MS documentation the v12 version.
(https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs)
To communicate with Azure Blob Storage, various methods such as Authentication, ConnectionString, SharedSASToken, and so on are available.
In this example, I’ll use the Access key in the Node JS API to interact with Azure Blob Storage.
Create a Node JS application:
At this point, our goal is to create NodeJS endpoints for operating files in Azure Blob Storage. So let’s build a Node JS application.
We will create a node js application and will install the required node js packages.
Define azure details in the .env file.
To keep things simple for you, I’ll write the entire code in one file (server.js).
You can verify files using the Azure Blob storage explorer tool.
https://azure.microsoft.com/en-in/features/storage-explorer/
Conclusion
I hope you found this tutorial on how to upload and delete files to azure blob storage using Node JS API useful. If you have any questions or thoughts, share them in the comments, I’ll be there!