Reputation: 71
I'm using loopback storage component "loopback-component-storage"
to upload files. But problem is after adding this storage component and a Model for it named as Container, I'm not able to migrate models in my application to database.
Following is error what i get
Error: Cannot create data source "storage": Cannot initialize connector "loopback-component-storage": FileSystemProvider: Path does not exist: ./server/files
at new FileSystemProvider
But I've /server/files directory as well in project described through this snapshot
Following is datasources.json file
{
"school": {
"host": "127.0.0.1",
"port": 3306,
"url": "",
"database": "school_db",
"password": "root",
"name": "school",
"user": "root",
"connector": "mysql"
},
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./server/files"
}
}
Following is model-config.json
(partially, not full)
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"Container": {
"dataSource": "storage",
"public": true
}
}
Following is Container (to upload/download files)
{
"name": "Container",
"plural": "containers",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
And following is my script to update model, say Address
var server = require('./../../server');
var ds = server.dataSources.school;
var tables = ['Address'];
ds.autoupdate(tables, function(er,result) {
if (er) throw er;
ds.discoverModelProperties('Address', function (err, props) {
console.log(props);
});
ds.disconnect();
});
Can someone please help me in figuring out the problem, why storage component is throwing exception of that files directory doesn't exist
Upvotes: 3
Views: 3510
Reputation: 11889
Just add another dot in front of your root directory.
"root": "../server/files"
The problem is your updation or migration script cannot find the directory. For me the migration script was in a bin directory and this directory structure was one level above.
Once the migration is done revert back.
Upvotes: 0
Reputation: 53
Do you have a files folder created inside the server folder?
If no? you have to create a folder named "files"
If yes? then your path declaration might be wrong. Try using full path like this
"root": "/home/ubuntu/Documents/project/server/files"
Upvotes: 0
Reputation: 118
Try adding this in server.js
var ds = loopback.createDataSource({
connector: require('loopback-component-storage'),
provider: 'filesystem',
root: 'server/files'
});
var storage = ds.createModel('storage');
app.model(storage);
check the documentation here too
Upvotes: 1
Reputation: 3729
I think issue in root parameter,
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./files"
}
Please refer : Link
https://strongloop.com/strongblog/working-with-file-storage-and-loopback/
Upvotes: 0