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

3

6

Image Showing CORS Error

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

Scoundrelly answered 31/12, 2020 at 16:55 Comment(5)
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.Stafford
The issue is with DigitalOcean. I'll edit the tags @StaffordScoundrelly
in that case below answer is related is for AWS S3 service so it might not help.Stafford
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 i.imgur.com/7ADSW42.png You can read more about how they are interoperable here: digitalocean.com/docs/spaces/resources/s3-sdk-examplesScoundrelly
I had similar problem but solved it in a different way (updating /etc/hosts). https://mcmap.net/q/507809/-access-control-allow-origin-header-missing-from-objects-even-after-adding-cors-settings-in-digitalocean-spaces-uiPlanetary
S
6

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

Scoundrelly answered 31/12, 2020 at 16:55 Comment(0)
G
1

Update, The Digital Ocean supports the localhost for now.

enter image description here

Gabo answered 28/1, 2024 at 11:25 Comment(0)
G
0

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

Genarogendarme answered 24/6, 2022 at 6:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.