LoopBack Storage Service

Class: StorageService(options)

Storage service constructor. Properties of options object depend on the storage service provider.

Arguments
Name Type Description
options Object

Options to create a provider; see below.

options
Name Type Description
provider String

Storage service provider. Must be one of:

  • 'filesystem' - local file system.
  • 'amazon'
  • 'rackspace'
  • 'azure'
  • 'openstack'

Other supported values depend on the provider. See the documentation for more information.

Class: StorageService Instance Methods

storageService.createContainer(options, cb)

Create a new storage service container.

Arguments
Name Type Description
options Object

Options to create a container. Option properties depend on the provider.

cb Function

Callback function

options
Name Type Description
name String

Container name

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

container Object

Container metadata object

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve Object

Container metadata object

storageService.destroyContainer(container, callback)

Destroy an existing storage service container.

Arguments
Name Type Description
container String

Container name.

callback Function

Callback function.

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve undefined The resolve handler does not receive any arguments.

storageService.download(container, file, req, res, cb)

Download middleware

Arguments
Name Type Description
container String

Container name

file String

File name

req Request

HTTP request

res Response

HTTP response

cb Function

Callback function

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve

storageService.downloadStream(container, file, options)

Get the stream for downloading.

Arguments
Name Type Description
container String

Container name.

file String

File name.

options Object

Options for downloading

Returns
Name Type Description
result Stream

Stream for downloading

storageService.getContainer(container, callback)

Look up a container metadata object by name.

Arguments
Name Type Description
container String

Container name.

callback Function

Callback function.

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

container Object

Container metadata object

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve Object

Container metadata object

storageService.getContainers(callback)

List all storage service containers.

Arguments
Name Type Description
callback Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

containers Array.<Object>

An array of container metadata objects

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve Array.<Object>

An array of container metadata objects

storageService.getFile(container, file, cb)

Look up the metadata object for a file by name

Arguments
Name Type Description
container String

Container name

file String

File name

cb Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

file Object

File metadata object

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve Object

File metadata object

storageService.getFiles(container, [options], cb)

List all files within the given container.

Arguments
Name Type Description
container String

Container name.

[options] Object

Options for download

cb Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

files Array.<Object>

An array of file metadata objects

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve Array.<Object>

An array of file metadata objects

storageService.removeFile(container, file, cb)

Remove an existing file

Arguments
Name Type Description
container String

Container name

file String

File name

cb Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided, a promise is returned instead (see below).

Name Type Description
err Object or String

Error string or object

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve undefined The resolve handler does not receive any arguments.

storageService.upload([container], req, res, [options], cb)

Upload middleware for the HTTP request/response

Arguments
Name Type Description
[container] String

Container name

req Request

Request object

res Response

Response object

[options] Object

Options for upload

cb Function

Callback function

Promise

This method supports both callback-based and promise-based invocation. Call this method with no callback argument to get back a promise instead.

Handler Argument Description
resolve

storageService.uploadStream(container, file, [options])

Get the stream for uploading

Arguments
Name Type Description
container String

Container name

file String

File name

[options] Object

Options for uploading

Returns
Name Type Description
result Stream

Stream for uploading

storageService.upload(provider, req, res, options, cb)

Handle multipart/form-data upload to the storage service

Arguments
Name Type Description
provider Object

The storage service provider

req Request

The HTTP request

res Response

The HTTP response

[options] Object

The container name

cb Function

Callback function

storageService.download(provider, req, res, container, file, cb)

Handle download from a container/file.

Arguments
Name Type Description
provider Object

The storage service provider

req Request

The HTTP request

res Response

The HTTP response

container String

The container name

file String

The file name

cb Function

Callback function.