0

I'm using the LoopBack storage component to upload and download files to azure cloud storage as illustrated on their documentation
I've created model named container in model-config.json

 "container": {
    "dataSource": "storage",
    "public": true
  }

with datasource in datasouce.json

"storage": {
    "name": "storage",
    "connector": "loopback-component-storage",
    "provider": 'azure',
    "storageAccount": "xxxxx",
    "storageAccessKey": "xxxx"
  }

Now I've a REST API, as described in their documentation. here's the error I've got each time I call one of the generated GET /api/containers endpoint.

{
  "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>"
    }
  }
}

after searching for this error I've found this answer my question is whether I have to set the header manually and how to do it or there's a missing configuration for azure storage for loopback-storage-component.

I added this piece of code to common/models/container.js and I get the same error.

module.exports = function(Container) {
  Container.beforeRemote('**', function(context, user, next) {
    //2015-12-11
    context.res.set('x-ms-version', '2015-12-11');
    next();
  });
};
Community
  • 1
  • 1
  • Try setting the header manually first and update your question – Jeroen Heier Nov 27 '16 at 11:50
  • To [list the containers](https://learn.microsoft.com/en-us/rest/api/storageservices/fileservices/List-Containers2?redirectedfrom=MSDN) under the specified account via REST API, **Authorization**, **Date** (or **x-ms-date**) and **x-ms-version** should be required in request header. Please use Fiddler to check the request headers and the actual values. – Fei Han Nov 28 '16 at 08:30

2 Answers2

0

I have tested the example-2.0 with the same configuration in model-config.json & datasouce.json with you, it works fine on my side without any other configuraitons or addtionally code modifications.

Could you provide more details about the environment and the sdk version you are using. You can try to update your dependencies, the dependencies in my test is:

"dependencies": {
    "compression": "^1.0.3",
    "errorhandler": "^1.1.1",
    "loopback": "^2.0.0",
    "loopback-boot": "^2.0.0",
    "loopback-component-explorer": "^2.1.0",
    "loopback-component-storage": "^1.5.0",
    "loopback-datasource-juggler": "^2.7.0",
    "serve-favicon": "^2.0.1"
  }

At last, you can try to modify the souce code of pkgcloud change 2011-08-18 to 2015-12-11 at https://github.com/pkgcloud/pkgcloud/blob/master/lib/pkgcloud/azure/utils/constants.js#L2048

Any further concern, please feel free to let me know.

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • I've tried the example-2.0 project with my configs and changed the dependencies in package.json. here's my dependencies `"dependencies": { "compression": "^1.0.3", "errorhandler": "^1.1.1", "loopback": "^2.22.0", "loopback-boot": "^2.6.5", "loopback-component-explorer": "^2.4.0", "loopback-component-storage": "^1.10.0", "loopback-datasource-juggler": "^2.39.0", "serve-favicon": "^2.0.1" }` – user3621876 Dec 02 '16 at 20:53
0

The problem was in the storage deployment type. I created storage with Azure classic deployment models however, when I changed the deployment model to "Azure Resource Manager" it worked well. The difference can be found here.