【发布时间】:2017-04-11 05:33:19
【问题描述】:
我正在使用 LoopBack 存储组件将文件上传和下载到 Azure 云存储,如他们的documentation 所示
我在 model-config.json 中创建了名为 container 的模型
"container": {
"dataSource": "storage",
"public": true
}
datasouce.json 中的数据源
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": 'azure',
"storageAccount": "xxxxx",
"storageAccessKey": "xxxx"
}
现在我有一个 REST API,如他们的文档中所述。这是我每次调用生成的 GET /api/containers 端点之一时遇到的错误。
{
"error": {
"name": "Error",
"status": 400,
"message": "azure Error (400): Bad Request",
"provider": "azure",
"failCode": "Bad Request",
"statusCode": 400,
"href": "http://xxxx.blob.core.windows.net/?comp=list",
"method": "GET",
"headers": {
"content-type": "application/xml",
"server": "Microsoft-HTTPAPI/2.0",
"x-ms-request-id": "820995fc-0001-013e-7b9a-48de28000000",
"date": "Sun, 27 Nov 2016 10:40:02 GMT",
"cache-control": "proxy-revalidate",
"content-length": "328",
"connection": "close"
},
"result": {
"err": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format.\nRequestId:820995fc-0001-013e-7b9a-48de28000000\nTime:2016-11-27T10:40:02.3522933Z</Message><HeaderName>x-ms-version</HeaderName><HeaderValue>2011-08-18</HeaderValue></Error>"
}
}
}
搜索此错误后,我发现 this 回答我的问题是我是否必须手动设置标头以及如何设置,或者缺少环回存储组件的天蓝色存储配置。
我将这段代码添加到 common/models/container.js 中,我得到了同样的错误。
module.exports = function(Container) {
Container.beforeRemote('**', function(context, user, next) {
//2015-12-11
context.res.set('x-ms-version', '2015-12-11');
next();
});
};
【问题讨论】:
-
尝试先手动设置标题并更新您的问题
-
通过REST API,授权,日期(或x-ms-date到指定帐户下的list the containers >) 和 x-ms-version 应该在请求标头中是必需的。请使用 Fiddler 检查请求头和实际值。
标签: node.js azure azure-blob-storage loopbackjs strongloop