Storage component for LoopBack.
Go to file
Raymond Feng 13e9097ff0 Refactor the storage service 2014-01-10 11:34:37 -08:00
example Refactor the storage service 2014-01-10 11:34:37 -08:00
lib Refactor the storage service 2014-01-10 11:34:37 -08:00
test Refactor the storage service 2014-01-10 11:34:37 -08:00
.gitignore Initial commits 2013-06-24 14:07:12 -07:00
LICENSE Update license file 2013-09-04 14:50:13 -07:00
README.md Update README 2013-10-23 21:23:28 -07:00
index.js Refactor the storage service 2014-01-10 11:34:37 -08:00
package.json Refactor the storage service 2014-01-10 11:34:37 -08:00

README.md

loopback-storage-service

LoopBack Storage Service

Storage

The loopback-storage-service module is designed to make it easy to upload and download files to various infrastructure providers.

To get started with a loopback-storage-service provider just create one:

  var storageService = require('loopback-storage-service')({
    //
    // The name of the provider (e.g. "file")
    //
    provider: 'provider-name',
  
    //
    // ... Provider specific credentials
    //
  });

Each compute provider takes different credentials to authenticate; these details about each specific provider can be found below:

  • Amazon

    { provider: 'amazon', key: '...', keyId: '...' }

  • Rackspace

    { provider: 'rackspace', username: '...', apiKey: '...' }

  • Azure

  • Local File System

    { provider: 'filesystem', root: '/tmp/storage' }

Each instance of storage.Client returned from storage.createClient has a set of uniform APIs:

Container

  • storageService.getContainers(function (err, containers) { })
  • storageService.createContainer(options, function (err, container) { })
  • storageService.destroyContainer(containerName, function (err) { })
  • storageService.getContainer(containerName, function (err, container) { })

File

  • storageService.upload(options, function (err) { })
  • storageService.download(options, function (err) { })
  • storageService.getFiles(container, function (err, files) { })
  • storageService.getFile(container, file, function (err, server) { })
  • storageService.removeFile(container, file, function (err) { })

Both the .upload(options) and .download(options) have had careful attention paid to make sure they are pipe and stream capable:

Upload a File

  var storage = require('loopback-storage-service'),
      fs = require('fs');
  
  var storageService = storage({ /* ... */ });
  
  fs.createReadStream('a-file.txt').pipe(storageService.uploadStream('a-container','remote-file-name.txt'));

Download a File

  var storage = require('loopback-storage-service'),
      fs = require('fs');
  
  var storageService = storage({ /* ... */ });
  
  storageService.downloadStream({
    container: 'a-container',
    remote: 'remote-file-name.txt'
  }).pipe(fs.createWriteStream('a-file.txt'));