2.1.12 • Published 6 years ago

imago-azure-blobs v2.1.12

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
6 years ago

Azure Blobs

This is a wrapper for Microsoft's azure-storage package for working with Azure blobs. It provides a more convenient syntax and async support.

Performance

It is best to cache the files stored in the cloud storage, because the retrieval times are 20-200 ms from within the same region, and 200-600 ms if the data is transferred between regions.

Initialization

The constructor takes the storage account name (e.g. myaccount) and the storage service key that you can find in Azure Portal after creating a storage account.

These credentials are better stored in the .env file. Then you can initialize the service as follows:

    const Blobs = require('imago-azure-blobs');
    global.blobs = new Blobs(
      process.env.AZURE_STORAGE_ACCOUNT, process.env.AZURE_STORAGE_ACCESS_KEY);

The reason to store the blobs service in the global variable is to avoid reestablishing the connection to the server each time the service is accessed from different parts of the code.

Methods

async initializeContainers(containers)

Initializes the containers, meaning it checks that the containers are created, or creates them.

The containers is an object in the following format:

const AZURE_BLOB_STORAGE_CONTAINERS = {
  MY_CONTAINER_1: { name: 'my-container-1', type: 'private' },
  MY_OTHER_CONTAINER: { name: 'my-other-container', type: 'public' },
};

The key is irrelevant and is for the programmer's convenience when calling other methods like writeFile. The name is the container name in Azure. The type can be private or public (allows anyone to download files via a public URL).

async writeFile(container, filename, content)

Write a file to storage.

async append(container, filename, content)

Append to a file in storage.

async readFile(container, filename)

Read a file from storage.

async exists(container, filename)

Check if file exists in storage.

Since each operation costs money, in some cases you can simply try to read a file using readFile(), and catch an exception if it doesn't exist.

getPublicDownloadLink(container, filename)

Get a public download URL for a filename. The container type must be set to public when it was first created.

Azure Tables

Azure Table storage is also supported.

Methods

constructor(storageAccount, storageAccessKey)

async initializeTables(tables)

Create tables if they don't exist. tables is an array of strings (table names).

async retrieveEntity(table, partition, key)

Read an entity from table.

async saveStringOnlyEntity(table, partition, key, data)

Save or replace entity with the specified key in database. data is an object where each key is a column name.

2.1.12

6 years ago

2.1.11

6 years ago

2.1.10

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago