如何从环回 post 存储 api 中的容器?
How can I post a container in Storage api from loopback?
我已经声明了我的数据源、我的模型和它们之间的连接器。
我的模型
{
"name": "container",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
数据源
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./server/storage"
}
我的提供商
{
"filesystem": {
"root": "./server/storage"
}
}
和连接器
"container": {
"dataSource": "storage",
"public": true
}
我尝试将类似 {"Object":"container1"} 的对象发布到路径“./server/storage”中,但我从回调中收到以下错误。
{
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Path must be a string. Received undefined",
"stack": "TypeError: Path must be a string. Received undefined.."
}
}
谁能帮我找到我的问题?谢谢!
post 容器的方法是,不使用环回 api。创建一个文件夹,该文件夹将成为您的提供程序路径(作为文件系统)的容器。
就这么简单!
您还可以使用 "name" 而不是 "Object" 作为 JSON 对象中的键,以使用 API 创建新的 container/directory。
POST /api/containers {"name":"container1"}
如果您需要一种编程方式来添加新容器,例如您想要为新用户创建某种文件系统。您可以使用下面的路线。 "Container" 是我给模特起的名字,你可以随便叫你的名字。
POST localhost:3000/api/container
在 post 请求的正文中,您必须有一个属性 name,name 的值可以是您正在创建的新容器。可以在 here 上找到的 Strongloop/Loopback 文档不准确,当您尝试 post 按照他们的指示操作时,您得到的错误也不准确。
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Path must be a string. Received undefined"
}
发送 post 请求以创建新容器的代码摘录也在下方。
var request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:3000/api/containers',
body: { name: 'someNewContainer' },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
我已经声明了我的数据源、我的模型和它们之间的连接器。
我的模型
{
"name": "container",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
数据源
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./server/storage"
}
我的提供商
{
"filesystem": {
"root": "./server/storage"
}
}
和连接器
"container": {
"dataSource": "storage",
"public": true
}
我尝试将类似 {"Object":"container1"} 的对象发布到路径“./server/storage”中,但我从回调中收到以下错误。
{
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Path must be a string. Received undefined",
"stack": "TypeError: Path must be a string. Received undefined.."
}
}
谁能帮我找到我的问题?谢谢!
post 容器的方法是,不使用环回 api。创建一个文件夹,该文件夹将成为您的提供程序路径(作为文件系统)的容器。 就这么简单!
您还可以使用 "name" 而不是 "Object" 作为 JSON 对象中的键,以使用 API 创建新的 container/directory。
POST /api/containers {"name":"container1"}
如果您需要一种编程方式来添加新容器,例如您想要为新用户创建某种文件系统。您可以使用下面的路线。 "Container" 是我给模特起的名字,你可以随便叫你的名字。
POST localhost:3000/api/container
在 post 请求的正文中,您必须有一个属性 name,name 的值可以是您正在创建的新容器。可以在 here 上找到的 Strongloop/Loopback 文档不准确,当您尝试 post 按照他们的指示操作时,您得到的错误也不准确。
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Path must be a string. Received undefined"
}
发送 post 请求以创建新容器的代码摘录也在下方。
var request = require("request");
var options = {
method: 'POST',
url: 'http://localhost:3000/api/containers',
body: { name: 'someNewContainer' },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});