Configuring CORS using CLI in IBM Cloud Object Storage Bucket

52 Views Asked by At
p@p:/home$ ibmcloud cos bucket-cors-put --bucket test --cors-configuration "./corsconfig.json"
FAILED
The value in flag '--cors-configuration' is invalid
NAME: 
   ibmcloud cos bucket-cors-put - Set the CORS configuration on a bucket

USAGE:
   ibmcloud cos bucket-cors-put --bucket BUCKET_NAME [--cors-configuration STRUCTURE] [--region REGION] [--output FORMAT] [--json]

OPTIONS:
   --bucket BUCKET_NAME            The name (BUCKET_NAME) of the bucket.
   --cors-configuration STRUCTURE  A STRUCTURE using JSON syntax in a file. See IBM Cloud Documentation.
   --region REGION                 The REGION where the bucket is present. If this flag is not provided, the program will use the default option specified in config.
   --output FORMAT                 Output FORMAT can be only json or text.
   --json                          [Deprecated] Output returned in raw JSON format.

I am receiving the above error when configuring cors on my bucket

corsconfig.json contents:

{
"CORSRules": [
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET"],
"AllowedOrigins": ["*"]
}
]
}

I tried using

  • relative path

  • absolute path

  • with and without quotes for the above

In the error it mentions:

Set the CORS configuration on a bucket

So I tried running:

p@p:/home$ ibmcloud target -r jp-tok
Switched to region jp-tok


                   
API endpoint:      https://cloud.ibm.com
Region:            jp-tok
User:              <my email>
Account:           <my account>
Resource group:    No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'
CF API endpoint:   
Org:               
Space:    

But there is a bucket in that region:

enter image description here

What am I missing, can someone help me out with it?

1

There are 1 best solutions below

1
Vidyasagar Machupalli On

As mentioned on the IBM Cloud documentation to set a Cloud Object Storage bucket CORS, you need to use the file:// prefix to load the JSON from a specified file.

ibmcloud cos bucket-cors-put --bucket test --cors-configuration file://corsconfig.json

JSON Syntax: --cors-configuration file://<filename.json> ======= The --cors-configuration command takes a JSON structure that describes the CORS configuration. In this example, the file:// prefix is used to load the JSON structure from the specified file.