1.0.5 • Published 2 years ago
@haddad_zineddine/azure-blob-storage v1.0.5
Azure Blob Storage
Description
Azure Blob Storage is a package for node js.
Before Installation
- Create a Storage account and resource
- In the Azure Portal, go to Dashboard > Storage > your-storage-account.
- Note down the "AccountName", "AccountKey" obtained at Access keys.
Installation
- Install the package using NPM:
$ npm i -S @haddad_zineddine/azure-blob-storage
- Create or update your existing
.env
file with the following content:
AZURE_STORAGE_ACCOUNT_NAME=
AZURE_STORAGE_ACCOUNT_KEY=
AZURE_STORAGE_CONTAINER_NAME=
IMPORTANT: Make sure to add your
.env
file to your.gitignore
! The.env
file MUST NOT be versionned on Git.Make sure to include the following call to your main file:
if (process.env.NODE_ENV !== 'production') require('dotenv').config();
This line must be added before any other imports!
- Set up the
AzureStorage
with the following configuration:
const azureStorage = AzureStorage.asyncSetUp({
accountName: process.env.AZURE_STORAGE_ACCOUNT_NAME
accountKey: process.env.AZURE_STORAGE_ACCOUNT_KEY
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME
});
- Upload
File
toAzure Blob Storage
:
const fileUrl : string = await azureStorage.uploadFile(file: UploadedFileMetadata);
- Delete
File
fromAzure Blob Storage
by it's blob name:
await azureStorage.deleteFile(blobName: String);
Stay in touch
- Author - Haddad Zineddine
License
MIT license.