Search code examples
loopbackjsstrongloop

specifying bucket-name in loopback-component-storage for S3


I have hit a roadblock using the loopback-component-storage with Amazon S3. As a test, I am trying to upload a file to S3 from my browser app, which is calling my loopback API on the backend.

My server config for datasources.json looks like:

  "s3storage": {
    "name": "s3storage",
    "connector": "loopback-component-storage",
    "provider": "amazon",
    "key": “blahblah”,
    "keyId": “blahblah”
  },

My API endpoint is: ‘/api/Storage’

The error response I am getting from the API is as follows:

.   error: {name: "MissingRequiredParameter", status: 500, message: "Missing required key 'Bucket' in params",…}
.   code: "MissingRequiredParameter"
.   message: "Missing required key 'Bucket' in params"
.   name: "MissingRequiredParameter"
.   stack: "MissingRequiredParameter: Missing required key 'Bucket' in params …”
.   status: 500
.   time: "2015-03-18T01:54:48.267Z"

How do i pass the {“params”: {“Bucket”: “bucket-name”}} parameter to my loopback REST API?

Please advice. Thanks much!


Solution

  • AFAIK Buckets are known as Containers in the loopback-component-storage or pkgcloud world.

    You can specify a container in your URL params. If your target is /api/Storage then you'll specify your container in that path with something like /api/Storage/container1/upload as the format is PATH/:DATASOURCE/:CONTAINER/:ACTION.

    Take a look at the tests here for more examples: https://github.com/strongloop/loopback-component-storage/blob/4e4a8f44be01e4bc1c30019303997e61491141d4/test/upload-download.test.js#L157