DigitalOceanTutorial2 min read

How Do I Use DigitalOcean Spaces for File Storage?

Store and serve files with DigitalOcean Spaces — S3-compatible object storage with a built-in CDN for fast global delivery.

Server racks and cloud infrastructure

What Are Spaces?

DigitalOcean Spaces is object storage — think of it as a cloud hard drive accessible over HTTP. It is S3-compatible, meaning you can use standard S3 tools and SDKs. Spaces includes a free CDN endpoint for fast file delivery worldwide. Pricing starts at $5/month for 250 GB of storage and 1 TB of outbound transfer.

Step 1 — Create a Space

In the control panel, go to Spaces Object Storage → Create a Space. Choose a region close to your users and pick a unique name (this becomes part of the URL). Select Restrict File Listing unless you want a public directory index.

Step 2 — Upload Files

Use the web UI to drag and drop files, or upload via the CLI:

# Install s3cmd or use the AWS CLI with DO credentials
aws configure --profile do
# Endpoint: https://nyc3.digitaloceanspaces.com
# Access key: from API → Spaces Keys

aws s3 cp photo.jpg s3://my-space/photos/ --profile do --endpoint-url https://nyc3.digitaloceanspaces.com

Step 3 — Enable the CDN

Each Space has a CDN endpoint at https://my-space.nyc3.cdn.digitaloceanspaces.com. Enable it under the Space's Settings → CDN. Files served through the CDN are cached at edge locations globally, reducing latency for your users.

Step 4 — Use Spaces from Your App

Install the AWS SDK (Spaces is S3-compatible):

npm install @aws-sdk/client-s3

Configure the client:

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';

const s3 = new S3Client({
  endpoint: 'https://nyc3.digitaloceanspaces.com',
  region: 'us-east-1',
  credentials: {
    accessKeyId: process.env.SPACES_KEY,
    secretAccessKey: process.env.SPACES_SECRET,
  },
});

Step 5 — Set Access Permissions

  • Public files (images, assets): set ACL to public-read on upload
  • Private files (user uploads, documents): keep ACL private and generate pre-signed URLs for temporary access

Common Use Cases

  • User-uploaded images for a web app
  • Static asset hosting (JS bundles, CSS, fonts)
  • Database backup storage
  • Log archival

Spaces keeps your Droplet disk lean by offloading files to dedicated, scalable storage with built-in CDN delivery.