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