To configure CORS on DigitalOcean Spaces and make it publicly accessible, you can set up permissions through the DigitalOcean control panel or use the DigitalOcean CLI. Here’s how to configure it:

1. Enable Public Access

To make your Space public:

  1. Go to the DigitalOcean Control Panel and navigate to Spaces.
  2. Select the Space you want to make public.
  3. Click on Settings.
  4. In the Permissions section, set File Listing to “Public.”
  5. Confirm by clicking Save.

This will make all objects in the Space accessible via a public URL.

2. Configure CORS Settings

You can define CORS rules directly in the Space’s settings:

  1. Go to Settings for your Space.
  2. Scroll down to CORS Configuration and click Edit CORS.
  3. Define the CORS configuration rules in JSON format. Here’s an example configuration to allow cross-origin access from any origin:

    [
    {
    "AllowedHeaders": ["*"],
    "AllowedMethods": ["GET", "POST", "HEAD"],
    "AllowedOrigins": ["*"],
    "ExposeHeaders": [],
    "MaxAgeSeconds": 3000
    }
    ]

    • AllowedHeaders: Specify headers allowed in requests. Use "*" to allow all headers.
    • AllowedMethods: Define HTTP methods like GET, POST, HEAD.
    • AllowedOrigins: Use "*" to allow requests from any origin, or specify specific domains.
    • ExposeHeaders: Specify headers exposed to the client.
    • MaxAgeSeconds: Defines how long the browser caches the CORS response.
  4. Click Save to apply your CORS settings.

Now, your DigitalOcean Space will allow public access and permit cross-origin requests.

That’s it.

Happy Sngine 🙂

Buy Sngine or Extend your support: https://bit.ly/BuySngine