How do I set a CORS policy on my bucket?

Expert

How do I set a CORS policy on my bucket?

Answers 2

The Filebase S3-compatible API supports CORS configurations for buckets. The following API methods are supported:

  1. GetBucketCors
  2. PutBucketCors
  3. DeleteBucketCors

Please see our documentation on configuring CORS policies:

https://docs.filebase.com/api-documentation/cross-origin-resource-sharing-cors/create-and-apply-a-cors-rule-to-a-filebase-bucket

The Filebase S3-compatible API supports CORS configurations for buckets. The following API methods are supported: GetBucketCors PutBucketCors DeleteBucketCors To configure a Filebase bucket to allow cross-origin requests, you will need to create a CORS rule. This rule identifies the origins that you will allow to access your bucket, the HTTP methods that will be supported for each origin, and other operation specific information. This rule can be a JSON or XML file, though if using AWS CLI to apply this rule, a .json file is required. Example #1 JSON: This example is a wildcard rule that allows cross-origin GET requests from all origins. { "CORSRules":[ { "AllowedHeaders": [], "AllowedMethods": [ "GET" ], "AllowedOrigins": [ "" ], "ExposeHeaders": [] } ] } Example #1 XML: GET Example #2 JSON: CORS also allows optional configuration parameters, as shown in the following CORS rule. MaxAgeSeconds: Specifies the amount of time in seconds that the browser caches a response to a preflight OPTIONS request for the specified resource. ExposeHeader: Identifies the response headers that customers are able to access from their applications. In this example, x-amz-server-side-encryption, x-amz-request-id, and x-amz-id-2. In this second example, the CORS rule allows cross-origin PUT, POST, and DELETE requests from the http://www.example.com origin, with a MaxAgeSeconds of 3000 and ExposeHeaders of x-amz-server-side-encryption, x-amz-request-id, and x-amz-id-2. { "CORSRules": [ { "AllowedHeaders": [ "” ], "AllowedMethods": [ "PUT", "POST", "DELETE" ], "AllowedOrigins": [ "http://www.example.com" ], "ExposeHeaders": [ "x-amz-server-side-encryption", "x-amz-request-id", "x-amz-id-2" ], "MaxAgeSeconds": 3000 } ] } Example #2 XML: http://www.example.com PUT POST DELETE 3000 x-amz-server-side-encryption x-amz-request-id x-amz-id-2 Applying a CORS Rule to a Filebase Bucket To apply a CORS rule, you can use a tool such as the AWS CLI to apply the .json file you created containing the rule. For information on how to configure AWS CLI, see here. From the command line, enter the following command to apply the CORS rule to the intended Filebase bucket: aws --endpoint https://s3.filebase.com s3api put-bucket-cors --bucket bucket-name --cors-configuration=file://corspolicy.json