IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 19 forks source link

Posting to encrypted bucket #30

Closed Conor-Quin closed 6 years ago

Conor-Quin commented 6 years ago

Is it possible to use .putObject() to POST data to an encrypted bucket. The bucket I am using is encrypted using IBM's Key Protect service.

When I try to use .putObject to POST data to the encrypted bucket the method just hangs but when I use a non encrypted bucket it works.

Any help would be greatly appreciated.

widget- commented 6 years ago

I've just tried it out on the us-south region with the latest SDK and it appears to be working fine.

putBucket should, as the name suggests, do a PUT operation rather than a POST.

Could you double-check that .putObject(...) is followed by .send(callback) or .promise()? Otherwise, if you have some code I can take a look.

Conor-Quin commented 6 years ago

Thank you for the reply.
I do have a .promise(). I've tested it many times and it definitely works for a non encrypted bucket but not with an encrypted bucket using Key Protect.

Here is the code I'm running. This create function gets called which then should use putObject() to place dataStr in to the bucket.


COSConnector.prototype.create = function create(model, data, callback){

  var key = guid();
  var dataStr = JSON.stringify(data); 

  return this.cos.putObject({
    "Bucket": this.bucket, 
    "Key": key, 
    "Body": dataStr,
  }).promise()
  .then(() => {

    data.id=key;
    this.response.push(data);
    callback(null, data);
  })
  .catch((e) => (`ERROR1: ${e.code} - ${e.message}\n`));    
}
Conor-Quin commented 6 years ago

These are 2 buckets I created, one encrypted with KP (indicated with the key) and the other not encrypted

kpbuck