Set CORS Rules
| Endpoint | Method | Admin Required |
|---|---|---|
/api/v1/buckets/:bucketName/cors | PUT | No |
Replaces the CORS rules of a bucket you own, overwriting the existing configuration entirely, like S3's PutBucketCors. To remove every rule use Delete CORS Rules - an empty rules array is rejected.
CORS rules decide which browser origins may call the S3-compatible API on this bucket: Alarik answers preflight OPTIONS requests and adds the Access-Control-* headers to S3 responses from the first rule that matches the request's origin, method and requested headers, in the order given. Without a configuration, browser requests to the bucket's S3 endpoints are refused by the browser. The rules are validated by the same code path as the S3 PUT ?cors subresource. They have no effect on this Internal API, whose CORS policy is fixed to the console's origin.
Path Parameters
Request Body
Rule fields
https://app.example.com. At least one. Each value may contain a single * wildcard (https://*.example.com, or * alone).GET, PUT, HEAD, POST, DELETE. At least one. Values are upper-cased for you.* wildcard. A preflight whose requested headers are not all covered does not match the rule.ETag, x-amz-version-id). No wildcards.0 or greater when set.Blank entries in any list are dropped before validation.
Example
{
"rules": [
{
"id": "web-app",
"allowedOrigins": ["https://app.example.com"],
"allowedMethods": ["GET", "PUT"],
"allowedHeaders": ["*"],
"exposeHeaders": ["ETag"],
"maxAgeSeconds": 3600
}
]
}
Response
Returns the saved rules:
{
"rules": [
{
"id": "web-app",
"allowedOrigins": ["https://app.example.com"],
"allowedMethods": ["GET", "PUT"],
"allowedHeaders": ["*"],
"exposeHeaders": ["ETag"],
"maxAgeSeconds": 3600
}
]
}
The new rules take effect on every node immediately.
Errors
| Status | Reason |
|---|---|
400 | Missing bucket name; rules empty or more than 100; an id longer than 255 characters; a rule without origins or methods; a method outside GET/PUT/HEAD/POST/DELETE; an origin or header with more than one *; an expose header containing *; a negative maxAgeSeconds |
404 | Bucket not found (or not owned by you) |