The storage connector enables LoopBack applications to interact with files on cloud storage providers and the local (server) file system.

See also:

Installation

If you haven’t yet installed the storage component, in your application root directory, enter:

  1. $ npm install loopback-component-storage --save

This will install the module from npm and add it as a dependency to the application’s package.json file.

Creating a storage data source

Create a new push data source with the data source generator.

When prompted, select other as the connector.

At the prompt “Enter the connector name without the loopback-connector- prefix,” enter storage.

This creates an entry in datasources.json like this (for example):

/server/datasources.json

  1. ...
  2. "myStorageDataSource": {
  3. "name": "myStorageDataSource",
  4. "connector": "loopback-component-storage"
  5. }
  6. ...

Configuring a storage data source

Configure a storage data source by editing the datasources.json file,for example as shown in the storage service example:

/server/datasources.json

  1. ...
  2. "myStorageDataSource": {
  3. "name": "myStorageDataSource",
  4. "connector": "loopback-component-storage",
  5. "provider": "filesystem",
  6. "root": "./server/storage"
  7. }
  8. ...

Creating a storage model

Use the model generator to create a new model, then edit the model.json file, as shown in the storage service example:

/server/models/container.json

  1. {
  2. "name": "container",
  3. "base": "Model",
  4. "properties": {},
  5. "validations": [],
  6. "relations": {},
  7. "acls": [],
  8. "methods": []
  9. }

Connect the model to the storage data source

/server/model-config.json

  1. ...
  2. "container": {
  3. "dataSource": "myStorageDataSource",
  4. "public": true
  5. }
  6. ...

Tags: connectors