0

I have created a IBM cloud Object storage service and i have created objects i.e image files in it.

I am looking for the steps to access the images as public URLs. I did some initial research and found there are cURL commands using swift Client to do this.

Reference links How to access files in container in Object Storage Service in Bluemix? AND Public URLs For Objects In Bluemix Object Storage Service

from the above links, it says the following steps

  1. Set up the swift CLI . Can you link me the steps to set up Swift CLI ? ( the link in the reference link dosen't work anymore ).

2.Change the container ACL to read with following PUT request

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

But i am not sure what to input on X-Auth-Token header ? i have the following information from the service credentials of 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::"
}

Any help would be really appreciated. Thanks

data_henrik
  • 16,724
  • 2
  • 28
  • 49
aram
  • 71
  • 1
  • 10

2 Answers2

1

The bearer token is from IAM. https://console.bluemix.net/docs/services/cloud-object-storage/getting-started-cli.html#gather-key-information

See this doc on generating pre-signed urls (temporary). https://console.bluemix.net/docs/services/cloud-object-storage/api-reference/api-reference-objects.html#object-operations

lifemikey
  • 86
  • 2
  • Thank you for response. I can able to get the bearer token from the first link you have provided. But not sure Which pre-signed URLs to be used from the object operations document ? – aram Sep 11 '18 at 15:16
  • Under **Upload an object** 1. set the HMAC headers Sample request (HMAC Headers) 2. create the pre-signed url Sample request (HMAC Pre-signed URL) – lifemikey Sep 11 '18 at 15:36
0

To do a one-off request like that, you can get oauth tokens from the command line using ibmcloud iam oauth-tokens. To specifically get an IAM Token, I use:

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

Then follow that up with your cURL command:

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

An application should request tokens based on the apiKey as mentioned.

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"

Here's an example using NPM's 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;
Van Staub
  • 81
  • 3