A promise wrapper for Azure Storage. Github repo
You can read about Azure Storage.
- Files
- Blobs
- Queues
If the outermost storage inside the resource, such as a share or container, doesn't exist, it is created as part of the request.
For Blob storage, the base directory is known as an empty string.
- Azure subscription
- Azure Storage resource and its connection string, found on the Keys page of the resource in the Azure portal.
npm install azure-storage-as-promised
The tests include usage of objects.
This method signature changed in V 0.9.0.
require('dotenv').config();
const BlobStorage = require("azure-storage-as-promised").Blob;
const myblob = new BlobStorage(process.env.AZURESTORAGECONNECTIONSTRING);
const container="function-blob-upload";
const directory=""; // root dir is empty string
const blob="short.txt";
const finalBlob = directory + '/' + blob;
myblob.getBlobProperties(container, blob).then(results=>{
console.log(JSON.stringify(results));
}).catch(err=>{
console.log(err);
})
// import classes in package
import { File } from 'azure-storage-as-promised';
// set connection string
const fileAzure = new File(process.env.AZURESTORAGECONNECTIONSTRING);
// create directory which creates share
const directoryResult = await fileAzure.createDirectory(share, directory, undefined);
// check that share does exist
const shareResult:any = await fileAzure.doesShareExist(share);
// check that directory does exist
const doesDirectoryExist = await fileAzure.doesDirectoryExist(share, directory);
// add file
const fileResult:any = await fileAzure.addFile(share, directory, fileName, fileFullPath, optionalContentSettings, optionalMetadata);
// get file properties
const fileProperties:any = await fileAzure.getFileProperties(share, directory, fileName);
// get file download
const url:any = await fileAzure.getFileUrl(share, directory, fileName);
// get base directories, empty string is base directory
const directoriesAndFiles:any = await fileAzure.getDirectoriesAndFiles(share, "");
// get subdir files
const subDirectoriesAndFiles:any = await fileAzure.getDirectoriesAndFiles(share, directoriesAndFiles.directories[0].name);
// delete directory and all files within
const deleteDirectoryResults:any = await fileAzure.deleteDirectory(share, directoriesAndFiles.directories[0].name);
// check that directory doesn't exist
const doesDirectoryExist2:any = await fileAzure.doesDirectoryExist(share, directory);
// delete Share
const deleteShareResult:any = await fileAzure.deleteShare(share);
npm run test
-
Version 0.9.0
Blob.getBlobProperties has new signature - directory is now a part of blob. For example, if directory is 'abc' and blob name is 'xyz', these are passing in as the blob variable, 'xyz/abc'.