For my node js project, I used an AWS S3 bucket and uploaded files from the front end using the AWS SDK.
Similarly, My file storage now needs to be migrated to Azure Blob Storage
Is there a way to upload directly to Azure Blob Storage from the client side?
Using Stack: Node Js (Javascript with EJS as Template engine)
I tried to build a bundle using browserify by passing the BlobServiceClient like this,
var { BlobServiceClient } = require("@azure/storage-blob");
window.BlobServiceClient = BlobServiceClient;
But its showing errors like TypeError: BlobServiceClient is not a constructor
In the end, I would like to replace the S3 bucket upload functions with Azure blob storage functions, and I would like to require the BlobServiceClient from "@azure/storage-blob" so I don’t have to change much code on the front end.
Please help with a solution to integrate the azure storage npm package into the browser.
2
Answers
I tried in my environment and successfully uploaded file in Azure blob storage using browser.
Before starting you need to install two packages.
Index.js
Index.html:
package.json
You can get the
Blob SAS-URL
by checking below image.Console:
Browser:
I copied the
Url
and pasted in browser it worked.After uploading it reflects done in browser.
Portal:
Reference:
Get started with Azure Blob Storage and JavaScript – Azure Storage | Microsoft Learn
https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/README.md?plain=1#L99