【问题标题】:Access Public URLs from IBM Cloud storage从 IBM Cloud 存储访问公共 URL
【发布时间】:2018-09-11 13:15:13
【问题描述】:

我创建了一个 IBM 云对象存储服务,并在其中创建了对象,即图像文件。

我正在寻找将图像作为公共 URL 访问的步骤。我做了一些初步研究,发现有使用 swift Client 的 cURL 命令来执行此操作。

参考链接 How to access files in container in Object Storage Service in Bluemix?Public URLs For Objects In Bluemix Object Storage Service

从上面的链接,它说以下步骤

  1. 设置 swift CLI。你能链接我设置 Swift CLI 的步骤吗? (参考链接中的链接不再起作用)。

2.更改容器ACL以读取以下PUT请求

curl -X PUT "https://dal.objectstorage.open.softlayer.com/v1/AUTH_123/mycontainer" \
    -H "X-Auth-Token: token123" \
    -H "X-Container-Read: .r:*"

但我不确定在 X-Auth-Token 标头上输入什么?我从 COS 的服务凭证中获得了以下信息。

{
  "apikey": "X7aDm6yu123123hXwqvq1231232HgOtIGeZiAOEg",
  "endpoints": "https://cos-service.bluemix.net/endpoints",
  "iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/f9aabca54c702be8386b2a3f9815b4e4:d145a33e-e8b1-446f-a87d-69431eaec0b1::",
  "iam_apikey_name": "auto-generated-apikey-bed16ed5-1373-47bc-b268-5e0f521bc802",
  "iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
  "iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/f9aabca54c702be8386b2a3f9815b4e4::serviceid:ServiceId-36c373a0-4bb9-4316-bc4b-86ea4c98dcd7",
  "resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/f9aabca54c702be8386b2a3f9815b4e4:d145a33e-e8b1-446f-a87d-69431eaec0b1::"
}

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 这看起来像一个真正的 API 密钥?!
  • 身份验证令牌通常是 IBM Cloud 的不记名令牌。
  • @data_henrik 抱歉,我在哪里可以找到 IBM COS 的不记名令牌?是 json 中的 apikey 字段吗?

标签: node.js ibm-cloud openstack-swift object-storage


【解决方案1】:

【讨论】:

  • 感谢您的回复。我可以从您提供的第一个链接中获取不记名令牌。但不确定要使用对象操作文档中的哪些预签名 URL?
  • 上传对象下 1.设置HMAC headers 示例请求(HMAC Headers) 2.创建预签名url 示例请求(HMAC Pre-signed URL)跨度>
【解决方案2】:

要执行这样的一次性请求,您可以使用ibmcloud iam oauth-tokens 从命令行获取 oauth 令牌。为了专门获取 IAM 令牌,我使用:

export IAM_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk ' {print $4} '`

然后用你的 cURL 命令跟进:

curl -H "Authorization: Bearer $IAM_TOKEN" ...

应用程序应根据上述 apiKey 请求令牌。

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Cache-Control: no-cache" -d 'apikey=<your api key here>&grant_type=urn:ibm:params:oauth:grant-type:apikey' "https://iam.bluemix.net/identity/token"

这是一个使用 NPM 的 request-promise 的示例:

const response = await rp({
  url: 'https://iam.bluemix.net/identity/token',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  method: "POST",
  body: `apikey=${apiKey}&grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey`,
  json: true
});

const token = response.access_token;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多