Page 223 - AngularJS权威教程
P. 223
18.20 查询 Dynamo 203
}); 1
});
// ...
最终,我们可以随上传的文件一起,把User对象保存在关联表中: 2
// ...
s3.getSignedUrl('getObject', params, 3
function(err, url) {
// 现在有了url
AWSService.dynamo({
params: {TableName: service.UserItemsTable} 4
}).then(function(table) {
var itemParams = {
Item: { 5
'ItemId': {S: file.name},
'User email': {S: user.email},
data: {
S: JSON.stringify({ 6
itemId: file.name,
itemSize: file.size,
itemUrl: url 7
})
}
}
}; 8
table.putItem(itemParams, function(err, data) {
d.resolve(data);
}); 9
});
});
// ...
10
这个方法的完整版在:https://gist.github.com/auser/7316267#file-services-js-L98。
我们可以在控制器的onFile方法中使用这个新方法,编写的代码类似于: 11
$scope.onFile = function(files) {
UserService.uploadItemForSale(files) 12
.then(function(data) {
// 刷新当前供出售的商品
});
} 13
18.20 查询 Dynamo 14
在理想情况下,我们想要能列出某个用户能购买的所有产品。为了列出这些可能购买的物品,
我们会使用query API。 15
Dynamo查询API有些深奥,乍一看相当混乱。
16
Dynamo的文档:http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/
API_Query.html。 17
我们基本上会使用比较操作符来匹配对象模式,比如说equal、lt(小于)、gt(大于),或
者其他任何更多的操作符。我们的连接表的键是User email键,所以我们要把这个键作为查询的 18