Matt Davis
Matt Davis

Reputation: 1337

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

Image Showing CORS Error

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

Upvotes: 6

Views: 4821

Answers (3)

Phat Tran
Phat Tran

Reputation: 3870

Update, The Digital Ocean supports the localhost for now.

enter image description here

Upvotes: 1

man.dev
man.dev

Reputation: 1

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

Upvotes: 0

Matt Davis
Matt Davis

Reputation: 1337

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

Upvotes: 6

Related Questions