Wrapper for Microsoft Azure blob storage
npm install @babl.one/storage-azure
babl.one framework that provides the app interfaces to store and retrieve files from Microsoft Azure Blob Storage. The plugin allows you to interact with Azure's Blob Storage service to manage files (upload, download, rename, and delete files).
@azure/storage-blob: Azure SDK for JavaScript to interact with Azure Blob Storage.
@babl.one/storage: Interface definitions for working with storage-related tasks in the babl.one framework.
fs: Node.js file system module for working with local files.
StorageAzure class implements the StorageAPI interface to interact with Azure Blob Storage.
init()
account and privateKey).
await storageAzure.init()
read(containerName: string, file: StorageFile)
containerName: The name of the container in Azure Blob Storage.
file: The file object containing the remote path and local path for the file.
file object.
await storageAzure.read('myContainer', file)
write(containerName: string, file: StorageFile)
containerName: The name of the container in Azure Blob Storage.
file: The file object containing the local path and blob data.
file object.
await storageAzure.write('myContainer', file)
delete(containerName: string, file: StorageFile)
containerName: The name of the container in Azure Blob Storage.
file: The file object containing the remote path for the file to be deleted.
file object.
await storageAzure.delete('myContainer', file)
rename(containerName: string, file: StorageFile)
containerName: The name of the container in Azure Blob Storage.
file: The file object containing the remote paths for the old and new file locations.
file object.
await storageAzure.rename('myContainer', file)
javascript
const storageAzure = new StorageAzure(config);
// Initialize the Azure Blob client
await storageAzure.init();
// Define the file object for the operation
const file = {
remotePath: 'path/to/remote/file',
localPath: '/path/to/local/file',
blob: null, // The file's data (for write operations)
status: 'PENDING',
};
// Read a file from Azure Blob Storage to local path
await storageAzure.read('myContainer', file);
// Upload a file to Azure Blob Storage
await storageAzure.write('myContainer', file);
// Delete a file from Azure Blob Storage
await storageAzure.delete('myContainer', file);
// Rename a file in Azure Blob Storage
await storageAzure.rename('myContainer', file);
`
Notes
- Ensure that the Azure credentials (account and privateKey`) are provided in the configuration.