我正在使用LoopBack存储组件上传和下载文件到azure Cloud 存储,如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 endpoints 之一时得到的错误 .
{
"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回答我的问题是我是否必须手动设置标头以及如何操作或者是否存在环回存储组件的azure存储配置 .
我将这段代码添加到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();
});
};
2 回答
我已经在
model-config.json
和datasouce.json
中使用相同的配置测试了example-2.0,它在我这边工作正常,没有任何其他配置或附加的代码修改 .您能否提供有关环境和您正在使用的sdk版本的更多详细信息 . 您可以尝试更新您的依赖项,我的测试中的依赖项是:
最后,您可以尝试修改
pkgcloud
的更改2011-08-18
的源代码https://github.com/pkgcloud/pkgcloud/blob/master/lib/pkgcloud/azure/utils/constants.js#L2048如有任何疑问,请随时告诉我 .
问题出在存储部署类型中 . 我使用Azure经典部署模型创建了存储,但是当我将部署模型更改为"Azure Resource Manager"时,它运行良好 . 可以找到差异here .