【问题标题】:How do I generate presigned links with the NodeJS SDK for IBM Cloud Object Storage?如何使用 NodeJS SDK for IBM Cloud Object Storage 生成预签名链接?
【发布时间】:2019-02-05 13:59:02
【问题描述】:

我正在使用 IBM Cloud Object Storage 及其 NodeJS SDK (https://github.com/IBM/ibm-cos-sdk-js)。

我想生成预签名链接,以便用户无需身份验证即可访问存储桶中的内容。

当我调用cos.getSignedUrl('getObject', ...) 时,我收到错误UnsupportedSigner: Presigning only supports S3 or SigV4 signing.

如何解决这个问题?

【问题讨论】:

    标签: node.js security amazon-s3 ibm-cloud object-storage


    【解决方案1】:

    首先,您需要为服务实例生成 HMAC 密钥,如 How do I create HMAC credentials for IBM Cloud Object Storage using the CLI? 中所述

    获得 HMAC 访问密钥和秘密访问密钥后,将 COS SDK 的初始化更改如下:

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

    然后您可以生成预签名链接:

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

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 1970-01-01
      • 2018-12-03
      • 2020-12-25
      • 2016-12-14
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多