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:
$ 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
...
"myStorageDataSource": {
"name": "myStorageDataSource",
"connector": "loopback-component-storage"
}
...
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
...
"myStorageDataSource": {
"name": "myStorageDataSource",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./server/storage"
}
...
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
{
"name": "container",
"base": "Model",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
Connect the model to the storage data source
/server/model-config.json
...
"container": {
"dataSource": "myStorageDataSource",
"public": true
}
...
Tags: connectors