简体   繁体   中英

Error using loopback-storage-component to upload/download files to azure storage

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();
  });
};

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM