0.3.0 • Published 3 years ago

dorsavi-storage v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Dorsavi.Storage

Usage

To use this library you will need a storage account, storage account key and container name as mandatory

To access individual blobs you will also need to know the name of the blob

  • sub1/sub2/test.png
  • test.png

The first example will look for a blob in sub folder 'sub1' under the root of the container and sub folder 'sub2' under 'sub1'

The second example will look for a blob in the root of the container

Supported modules

The library is compiled for ECMA modules as NodeJS supports ECMA modules now.

Security and storage account details

The library uses the following environment variables to store the

  • Storage account name
    • ACCOUNT_KEY

  • Storage account key
    • ACCOUNT_NAME

If these are not defined you will need to pass them to package from wherever you want to store them I suggest, securely.

Azure KeyVault integration is coming soon.

Supported methods

  • Get
    • Gets the blob information including meta data, this does not retrieve the blob use the "Download" method described below.
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
      • blob:string The name of the blob or file name including folders i.e sub1/sub2/test.png
  • Upload
    • Upload a blob to the specified container in the specified storage account
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
      • blobName:string The name of the blob including any folders i.e sub1/sub2/test.png
      • content:string The text or string content to be uploaded to the blob
      • metaData:IMetaData The required Metadata see below for the allowed properties
      • onProgress:any A callback method that will be called on progress events from the blob upload it will contain a property called loadedBytes which is the current total byte upload count e.g 1024 bytes
  • UploadFile
    • Upload a blob to the specified container in the specified storage account
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
      • blobName:string The name of the blob including any folders i.e sub1/sub2/test.png
      • filePath:string The local file name of the file to upload to the blob
      • metaData:IMetaData The required Metadata see below for the allowed properties
      • onProgress:any A callback method that will be called on progress events from the blob upload it will contain a property called loadedBytes which is the current total byte upload count e.g 1024 bytes
  • UploadStream
    • Upload a blob to the specified container in the specified storage account
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
      • blobName:string The name of the blob including any folders i.e sub1/sub2/test.png
      • fileStream:internal.Readable An internal.Readable stream to be uploaded to the blob
      • metaData:IMetaData The required Metadata see below for the allowed properties
      • onProgress:any A callback method that will be called on progress events from the blob upload it will contain a property called loadedBytes which is the current total byte upload count e.g 1024 bytes
  • Download
    • Download the blob contents
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
  • List

    • Get a list of blobs in this container
    • Parameters
      • storageAccountName:string The name of the azure storage account
      • storageAccountKey:string The key to be used to generate the SAS query parameters
      • containerName:string The name of the container to search for the blob
  • Metadata

    • There is certain properties or Metadata required to be stored with the blob this will also be used to determine the correct path of where to store the blob in the container below is a list of properties that must be included any other properties will be ignored

      Note that all of the fields are strings

      • AccountId:string The unique guid for the account
      • AccountName:string The text name of the account
      • AssessmentCreatedBy:string The name of the person creating the assessment file
      • AssessmentId:string The unique guid for the assessment
      • AssessmentName:string The name of this assessment
      • AssessmentTypeId:string The unique integer number specifying the assessment type i.e "1"
      • AssessmentType:string The text description that matches the TypeId i.e "Live assessment"
      • SiteId:string The unique guid for the site associated to the account
      • SiteName:string The text name of the site
      • Locale:string The locale where this assessment is being created i.e 'Australia/Melbourne'

Exceptions

Exceptions are thrown for example if a blob cannot be found

A custom error will be re thrown under a try catch which has the basic information from Azure i.e 404, BlobNotFound

Supported exceptions

  • 404, Azure code details, BlobNotFound
  • 400, Azure code details, Bad request
  • 401, Azure code details, Unauthorized