I want to implement a REST API to control the access to an IBM Bluemix Object Storage. The POST method is implemented and works fine, but there is a problem by deleting the created object, because I get de following error:
TypeError: Key must be a buffer
The code looks like this:
var AWS = require('ibm-cos-sdk');
var util = require('util');
var config = {
endpoint: <endpoint url>,
apiKeyId: <api key code>,
ibmAuthEndpoint: 'https://iam.ng.bluemix.net/oidc/token',
serviceInstanceId: <instance code>,
signatureVersion: 'v4'
};
var cos = new AWS.S3(config);
app.delete('/<path>/:id',function(req, res){
cos.deleteObject({
Bucket: <bucket>,
Key: req.params.id + '.pdf'
}, function(err, data){
if(err){
console.log("ERROR: " + err);
res.send({"message":"error: " + err});
} else {
console.log("data: " + data);
res.send({"message": "success"});
}
});
});
Does someone know the problem and can help?
It looks like this issue is when one of the encryption libraries encounters a string or buffer that's similar to a string or buffer but isn't actually one. I'm a little curious how that happened, though it shouldn't matter for this issue.
It turns out it's caused by signatureVersion: v4
which has the SDK building signatures it doesn't need. Removing signatureVersion
from your config should fix it. That will default back to the iam
signature type, which is what is used with API keys.