1.0.5 • Published 3 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
.envfile with the following content:
AZURE_STORAGE_ACCOUNT_NAME=
AZURE_STORAGE_ACCOUNT_KEY=
AZURE_STORAGE_CONTAINER_NAME=IMPORTANT: Make sure to add your
.envfile to your.gitignore! The.envfile 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
AzureStoragewith 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
FiletoAzure Blob Storage:
const fileUrl : string = await azureStorage.uploadFile(file: UploadedFileMetadata);- Delete
FilefromAzure Blob Storageby it's blob name:
await azureStorage.deleteFile(blobName: String);Stay in touch
- Author - Haddad Zineddine
License
MIT license.