Constructor
new Blocklift()
Creates a new Blocklift client for Azure Storage for blobs (binary large objects).
Parameters
-
opts.account
String
Blob Storage Account name
-
opts.accessKey
String
Blob Storage Account Access Key
Example
const lift = new Blocklift({
account: 'your account name',
accessKey: 'your access key',
defaultContainer: 'your-default-container' // must already exist
})
Source
Members
accountString
Azure Storage Account name e.g. mystorageaccount
Type
-
String
Source
defaultContainerString|Object
Name of default container for blobs, used if container is not specified in API calls.
Type
-
String
|Object
Source
Methods
createContainer(name) → {Promise}
Creates a new container
Will throw an error if name is not all lowercase.
Parameters
-
name
String
will be transformed to lowercase per Azure requirements
Returns
-
Promise
Example
lift.createContainer('name')
Source
deleteBlob(pathname, optsopt) → {Promise}
Deletes a Blob from the Storage Account
Parameters
-
pathname
String
path to file
-
opts
Object
<optional>
Properties
-
container
String
<optional>
file's container name
-
container
Returns
-
Promise
Examples
lift.deleteBlob('folder/image.png') // uses default container
lift.deleteBlob('folder/image.png', { container: 'my-container' })
{
name: 'container-2020-03-22-1519-a7uotq',
operation: 'delete',
message: 'Successfully deleted container container-2020-03-22-1519-a7uotq',
serverResponse: {
clientRequestId: '0cf51581-ebbe-4b4c-aaca-4d31bbad1b58',
requestId: '0a6759b4-a01e-0054-0154-00ea78000000',
version: '2019-02-02',
date: 2020-03-22T14:19:55.000Z,
errorCode: undefined,
'content-length': '0',
server: 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0',
body: undefined
}
}
Source
deleteContainer(name) → {Promise}
Delete a container
Parameters
-
name
String
container name
Returns
-
Promise
Example
lift.deleteContainer('name')
Source
getBlobUrl(pathname, containeropt) → {String}
Helper that returns URL for a given blob in a given container, e.g. https://myaccount.blob.core.windows.net/default/my-image.png
Parameters
-
pathname
String
path to file
-
container
String
<optional>
container name
Returns
-
String
Example
lift.getBlobUrl('my-image.png')
Source
listBlobs(containerNameopt) → {Promise.<Array>|Promise.<Object>}
List Blobs in a container or defaultContainer
if none is provided.
Parameters
-
containerName
String
<optional>
Returns
-
Promise.<Array>
list of blobs
-
Promise.<Object>
Error
Example
// list blobs in default container
lift.listBlobs()
// list blobs in specific container
lift.listBlobs('container')
Source
listContainers() → {Promise.<Array>|Promise.<Object>}
List Containers
Returns
-
Promise.<Array>
list of containers
-
Promise.<Object>
Error
Examples
lift.listContainers()
[
{
name: 'container-1',
properties: {…},
metadata: undefined
},
{
name: 'container-2',
properties: {…},
metadata: undefined
}
]
Source
upload(pathname, content, optsopt) → {Promise}
Upload content
at the moment not recommended because it does not include headers
for example Content-Type
Parameters
-
pathname
String
-
content
String
-
opts
*
<optional>
{}
Returns
-
Promise
Examples
lift.upload('hello.txt', 'Hello World', { contentType: 'text/plain' })
{
url: 'https://myaccount.blob.core.windows.net/default/hello-2020-03-22.txt',
serverReponse: {
etag: '"0x8D7CE6FCC47FC45"',
lastModified: 2020-03-22T14:46:26.000Z,
contentMD5: <Buffer c4 85 73 58 38 b0 05 75 7f 3f 31 99 50 0c 0e ca>,
clientRequestId: 'd749b9a2-5fba-489d-a230-ba5df662f4f0',
requestId: '283595f3-a01e-0009-1b58-00e0fc000000',
version: '2019-02-02',
date: 2020-03-22T14:46:25.000Z,
isServerEncrypted: true,
encryptionKeySha256: undefined,
errorCode: undefined,
'content-length': '0',
server: 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0',
'x-ms-content-crc64': 'awyymjQimGI=',
body: undefined
}
}
Source
uploadFile(sourcePath, blobPath, optsopt) → {Promise}
Upload a file. Blocklift will attempt to set the Content-Type
for you
based on file extension and/or contents.
Parameters
-
sourcePath
String
source file pathname
-
blobPath
String
desintation file pathname on Azure
-
opts
Object
<optional>
{}
Returns
-
Promise
Examples
lift.uploadFile('local-file.png', 'folder/image.png')
{
url: 'https://myaccount.blob.core.windows.net/default/hello-2020-03-22.txt',
serverReponse: {…}
}