从IBM Cloud存储访问公共URL

时间:2018-09-11 13:15:14

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

我已经创建了IBM cloud Object存储服务,并且已经创建了对象,即其中的图像文件。

我正在寻找将图像作为公共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. 设置快速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::"
}

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

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

要执行这样的一次性请求,您可以使用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的请求承诺的示例:

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;