Can't add http://localhost to DigitalOcean Spaces CORS Rules

Viewed 1715

Image Showing CORS Error

As you can see from the image is it not currently possible to add http://localhost as a CORS rule.

2 Answers

In order to fix this issue you must use a tool such as s3cmd. The easiest way to use this tool is by downloading the source. If you already have Python installed you can use the following commands to change DigitalOcean Spaces CORS configuration (requires python 2.7 or greater):

Note: You may also need to have Gpg4win installed.

First download the source from here and extract into any directory. Then run the following commands in that directory. You should also place your cors.xml config within this directory.

python s3cmd --configure

This is an example input for the config hosted on Amsterdam 3....

Access Key [YOUR_ACCESS_KEY]:
Secret Key [YOUR_SECRET_KEY]: 
S3 Endpoint [ams3.digitaloceanspaces.com]
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.ams3.digitaloceanspaces.com]:
Encryption password [password]:

python s3cmd ls - View all of your spaces

python s3cmd setcors cors.xml s3://your-space-name-here where cors.xml is a file in your working directory containing a standard cors configuration such as:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://localhost:4000</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
   <AllowedMethod>HEAD</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

After running this final command you should now see in your DigitalOcean dashboard that your original CORS configuration has now been replaced with whatever configuration you saved to cors.xml

Another option is to add an entry to your local host file

127.0.0.1 local.test.com

and instead of:

localhost

use:

local.test.com

Related