Report this

What is the reason for this report?

Spaces CDN read VS write files and Django settings?

Posted on September 1, 2023

On the how-to for deploying Scalable Django app., there are instructions for the settings, adding.

AWS_S3_CUSTOM_DOMAIN = 'spaces_edge_endpoint_URL'

What is not clear to me, does this URL allow writing to the also? Or do I need to somehow configure separate read and write URLs?

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-django-app-with-digitalocean-managed-databases-and-spaces#enabling-cdn-optional



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

When integrating Django with DigitalOcean Spaces using the CDN, the AWS_S3_CUSTOM_DOMAIN typically refers to the CDN endpoint of the Space for reading (i.e., serving static/media files). The purpose of using the CDN endpoint is to distribute the content globally to reduce latency for users fetching those assets.

For writing (i.e., uploading files to the Space), Django will use a different endpoint which will be the DigitalOcean Space’s endpoint (not the CDN endpoint). This distinction is managed internally by the libraries you use (like django-storages with the S3 backend).

To clarify:

  1. Reading Files (Serving): Your Django app will serve static and media files using the CDN endpoint (e.g., your-space-name.nyc3.cdn.digitaloceanspaces.com). This is where AWS_S3_CUSTOM_DOMAIN comes into play when you want to serve these assets using the CDN.

  2. Writing Files (Uploading): When your Django app needs to upload a file to the Space, it will use the endpoint associated with your Space directly (e.g., nyc3.digitaloceanspaces.com). This is typically managed through the AWS_STORAGE_BUCKET_NAME and AWS_S3_REGION_NAME settings in conjunction with the library.

To answer your concern directly: No, you don’t need to configure separate read and write URLs in your Django settings when using the typical django-storages setup for DigitalOcean Spaces. The AWS_S3_CUSTOM_DOMAIN is primarily for reading (serving) files through the CDN, while writing (uploading) is managed internally by the library.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.