我创建了一个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
从上面的链接,它说以下步骤
2.使用以下PUT
请求更改容器ACL以读取
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::"
}
任何帮助将非常感激。谢谢
要执行这样的一次性请求,您可以使用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;