1

I'm using IBM Cloud Object Storage and its NodeJS SDK (https://github.com/IBM/ibm-cos-sdk-js).

I want to generate presigned links so that users can access contents in the bucket without the need to authenticate.

When I call cos.getSignedUrl('getObject', ...), I get the error UnsupportedSigner: Presigning only supports S3 or SigV4 signing.

How to solve this issue?

Frederic Lavigne
  • 704
  • 3
  • 12

1 Answers1

2

First you need to generate HMAC keys for your service instance as described in How do I create HMAC credentials for IBM Cloud Object Storage using the CLI?

Once you have the HMAC access key and secret access key, change the initialization of the COS SDK as follow:

const config = {
  endpoint: 'cos endpoint',
  apiKeyId: 'cos api key',
  ibmAuthEndpoint: 'https://iam.ng.bluemix.net/oidc/token',
  serviceInstanceId: 'cos crn'
  // these two are required to generate presigned URLs
  credentials: new COS.Credentials('<access key>', '<secret_access_key>', sessionToken = null),
  signatureVersion: 'v4'
};
const cos = new COS.S3(config);

then you can generate presigned links with:

const url = await cos.getSignedUrl('getObject', {
  Bucket: '<your-bucket-name>',
  Key: '<your-key-name>',
  Expires: 60 * 5, // 5 minutes
});
Frederic Lavigne
  • 704
  • 3
  • 12