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

- 1,167
- 8
- 21
-
just out of curiosity is this the problem with AWS S3 or we are talking about Digital ocean because in the attached screenshot as well as in the question header digital ocean it seems to me. But the tags are amazon web services. – samtoddler Dec 31 '20 at 17:10
-
The issue is with DigitalOcean. I'll edit the tags @samtoddler – Matt Davis Dec 31 '20 at 17:46
-
in that case below answer is related is for AWS S3 service so it might not help. – samtoddler Dec 31 '20 at 17:48
-
It will, the DigitalOcean API is compatible with most Amazon S3 SDKs and functions. For example you can include Amazon's `aws-sdk` npm package in Node and it will work as a plug-and-play replacement when using DigitalOcean like so https://i.imgur.com/7ADSW42.png You can read more about how they are interoperable here: https://www.digitalocean.com/docs/spaces/resources/s3-sdk-examples/ – Matt Davis Dec 31 '20 at 17:50
-
I had similar problem but solved it in a different way (updating `/etc/hosts`). https://stackoverflow.com/a/70315253/331655 – Amrit Dec 11 '21 at 12:50
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

- 1,167
- 8
- 21
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

- 1