我创建了一个IBM云对象存储服务,并在其中创建了对象,即图像文件。
我正在寻找的步骤,以访问图像作为公共网址。我做了一些初步的研究,发现有一些cURL命令使用快速客户端来完成。
参考链接How to access files in container in Object Storage Service in Bluemix?和Public URLs For Objects In Bluemix Object Storage Service
从上面的链接中,它指出了以下步骤
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::"
}任何帮助都会很感激的。谢谢
发布于 2018-09-11 14:00:41
发布于 2018-09-14 17:26:25
要执行这样的一次性请求,可以使用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;https://stackoverflow.com/questions/52276817
复制相似问题