我想使用Loopback存储服务将文件上传到存储容器.
但是.upload()方法需要一个请求对象.但是,如果我想上传一个不是来自提交表单的现有文件呢?
我是否需要伪造POST请求以使上传处理程序满意?似乎必须有更好的方法.
我有两个通过hasMany关系相关的模型.
Customer 有很多 CustomerPhones
在创建新内容时Customer,我想将相关内容CustomerPhones作为单个请求的一部分传递.这似乎是一种常见的需求,如果我想要实现的方法是错误的,那么这样做的首选方法是什么?
这是创建客户的URL: POST /api/Customers
上面url的请求将是req.body
{
"name": "Foo",
"customerPhones": [
{ "phoneNumber": "8085551234" },
{ "phoneNumber": "8085554567" }
]
}
Run Code Online (Sandbox Code Playgroud)
Loopback模型配置:
Customer.json
{
"name": "Customer",
"base": "User",
"properties": {
"name": {
"type": "string",
"required": true
}
},
"relations": {
"customerPhones": {
"type": "hasMany",
"model": "CustomerPhone",
"foreignKey": ""
}
}
}
Run Code Online (Sandbox Code Playgroud)
CustomerPhone.json
{
"name": "CustomerPhone",
"base": "PersistedModel",
"properties": {
"phoneNumber": {
"type": "string",
"required": true
},
"customerId": {
"type": "number",
"required": true …Run Code Online (Sandbox Code Playgroud) 我正在使用Loopback来创建Rest API.需要根据集合中的特定列获取不同的数据.我在下面尝试过,但它不起作用,而下面的代码片段也提取重复数据:
this.app.models.location.find(
{
distinct: ("regionName",
{state: st})
}
,
function(err, location){........}
Run Code Online (Sandbox Code Playgroud)
'RegionName'是'location'集合的属性,我只需要选定状态的数据(state是location集合的另一个属性),由'st'表示.谢谢.