Media Sharing in a Chat App: Uploads, Object Storage, CDN and Thumbnails

Design photo, video and document sharing for a chat app: pre-signed uploads, resumable transfers, encryption, thumbnails, CDN delivery, dedup and retention.

Published November 27, 2026

Text messages are tiny; photos, voice notes and videos are not. Media is by far the largest share of a chat app's bandwidth and storage, and it must never travel through the same servers that handle real-time messages. The standard design separates the two: media goes to object storage via direct uploads, and the chat message carries only a small reference.

The concept

When a user attaches a photo, the client first uploads the file, then sends a normal chat message containing a media reference (an ID or URL, size, type, thumbnail and decryption key). The recipient's client sees the reference and downloads the file from storage or a CDN, often lazily when the message scrolls into view.

Uploads should bypass application servers entirely. The client asks the API for a pre-signed upload URL and sends the bytes straight to object storage (S3, GCS, Azure Blob or MinIO). For large files and poor networks, multipart or resumable uploads let a 200 MB video continue after a dropped connection instead of restarting. In end-to-end encrypted apps the client encrypts the file with a random key before upload, so storage holds only ciphertext and the key travels inside the encrypted message.

The media flow

Sender appMedia APIObject storageRecipient apprequest upload URLpre-signed PUT URLPUT encrypted byteschat msg: media id + key + thumbGET via CDN, decrypt locally
Media bypasses the chat servers; messages carry only references.

Design decisions

ConcernDesign choice
Upload pathPre-signed URLs direct to object storage; multipart/resumable for large files
Download pathCDN in front of storage; signed or unguessable URLs
PrivacyClient-side encryption with a per-file key sent inside the E2EE message
PreviewsClient generates a tiny blurred thumbnail embedded in the message
BandwidthClient-side compression and transcoding; size limits per type
ForwardingRe-reference the same encrypted blob instead of re-uploading
RetentionLifecycle rules delete blobs after delivery or after N days

Why compression and thumbnails matter

Original photo4.8 MBClient-compressed JPEG/WebP≈220 KBInline blurred thumbnail≈1.5 KB
Typical sizes for one smartphone photo at each stage.

Thumbnails and transcoding with E2EE

Without E2EE, servers can generate thumbnails and transcode videos into adaptive bitrates after upload, using a queue and workers. With E2EE, the server cannot see the media, so the sending client does that work: it resizes images, compresses video, and embeds a small blurred thumbnail (a few hundred bytes to a couple of kilobytes) in the message so the recipient sees a preview instantly.

Practical examples

Issue a pre-signed upload URL (Node.js, AWS SDK v3)

The URL is valid for a few minutes and only for this object key and content type.

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import { randomUUID } from 'node:crypto'

const s3 = new S3Client({ region: 'ap-south-1' })
export async function createUpload(userId, contentType, size) {
  if (size > 100 * 1024 * 1024) throw new Error('file too large')
  const key = `media/${userId}/${randomUUID()}`
  const url = await getSignedUrl(s3, new PutObjectCommand({
    Bucket: 'chat-media', Key: key, ContentType: contentType, ContentLength: size,
  }), { expiresIn: 300 })
  return { key, url }
}

Media reference inside the message

Everything the recipient needs, encrypted end to end along with the message.

{
  "media": {
    "id": "media/42/7d1f...",
    "mime": "image/jpeg",
    "size": 221934,
    "sha256": "9f2c...",
    "key": "base64-aes-key",
    "thumb": "base64-tiny-blurred-jpeg",
    "width": 1600, "height": 1200
  }
}

Lifecycle rule to expire media

Delete blobs automatically after 30 days.

{
  "Rules": [{ "ID": "expire-chat-media", "Status": "Enabled",
              "Filter": { "Prefix": "media/" },
              "Expiration": { "Days": 30 } }]
}

Common mistakes

  • Uploading media through application servers, tying up workers and bandwidth.
  • Public, guessable media URLs that let anyone enumerate private photos.
  • No resumable uploads, so large videos repeatedly fail on mobile networks.
  • Server-side thumbnailing in an E2EE app, which requires seeing plaintext.
  • Never deleting delivered media, letting storage costs grow forever.

Key takeaways

  • Upload directly to object storage with pre-signed URLs; send only references in messages.
  • Serve downloads through a CDN with signed or unguessable URLs.
  • With E2EE, encrypt and thumbnail on the client.
  • Use lifecycle policies and dedup to control storage cost.

FAQ

How does forwarding avoid re-uploading?

The forwarded message reuses the same encrypted blob reference and key, so only the small message is sent again.

Can the CDN cache encrypted media?

Yes. Ciphertext is just bytes; caching it at the edge is safe because only key holders can decrypt it.

How are voice notes handled?

The same way: recorded and compressed on the device (for example Opus), encrypted, uploaded, and referenced in a message.

More Architecture articles