Filebase
Search…
Create and Apply a CORS Rule to a Filebase Bucket
Learn how to configure a basic CORS rule for use with a Filebase bucket.
Cross-origin resource sharing (CORS) creates a way for client web applications located on one domain to have the ability to interact with resources located on a different domain. With CORS, websites and applications can access files and resources stored on Filebase buckets.

Creating a CORS Rule for 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.
1
{
2
"CORSRules":[
3
4
{
5
6
"AllowedHeaders": [],
7
8
"AllowedMethods": [
9
10
"GET"
11
12
],
13
14
"AllowedOrigins": [
15
16
"*"
17
18
],
19
20
"ExposeHeaders": []
21
22
}
23
24
]
25
}
Copied!
Example #1 XML:
1
<CORSConfiguration>
2
3
<CORSRule>
4
5
<AllowedOrigin>*</AllowedOrigin>
6
7
<AllowedMethod>GET</AllowedMethod>
8
9
</CORSRule>
10
11
</CORSConfiguration>
Copied!
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.
1
{
2
"CORSRules": [
3
4
{
5
6
"AllowedHeaders": [
7
8
"*"
9
10
],
11
12
"AllowedMethods": [
13
14
"PUT",
15
16
"POST",
17
18
"DELETE"
19
20
],
21
22
"AllowedOrigins": [
23
24
"http://www.example.com"
25
26
],
27
28
"ExposeHeaders": [
29
30
"x-amz-server-side-encryption",
31
32
"x-amz-request-id",
33
34
"x-amz-id-2"
35
36
],
37
38
"MaxAgeSeconds": 3000
39
40
}
41
42
]
43
}
Copied!
Example #2 XML:
1
<CORSConfiguration>
2
3
<CORSRule>
4
5
<AllowedOrigin>http://www.example.com</AllowedOrigin>
6
7
<AllowedMethod>PUT</AllowedMethod>
8
9
<AllowedMethod>POST</AllowedMethod>
10
11
<AllowedMethod>DELETE</AllowedMethod>
12
13
<AllowedHeader>*</AllowedHeader>
14
15
<MaxAgeSeconds>3000</MaxAgeSeconds>
16
17
<ExposeHeader>x-amz-server-side-encryption</ExposeHeader>
18
19
<ExposeHeader>x-amz-request-id</ExposeHeader>
20
21
<ExposeHeader>x-amz-id-2</ExposeHeader>
22
23
</CORSRule>
24
25
</CORSConfiguration>
Copied!

Applying a CORS Rule to 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:
1
aws --endpoint https://s3.filebase.com s3api put-bucket-cors \
2
--bucket bucket-name \
3
--cors-configuration=file://corspolicy.json
Copied!

Testing the CORS configuration

You can confirm that the CORS configuration for the bucket was applied successfully by using the command:
1
aws --endpoint https://s3.filebase.com s3api get-bucket-cors \
2
--bucket bucket-name
Copied!
For a full list of supported S3 API calls, see here.
If you have any questions, please send us an email at [email protected].
Last modified 12d ago