All case studies

My own photos wouldn’t upload

I was writing a post on Planit Traveler and added five photos to a carousel. Two or three appeared, and the rest silently didn’t. The cause was a safety check running one step too early, and an editor that kept the error to itself.

Project
Planit Traveler, blog editor and image uploads
My part
Found and reported it, directed the fix with Claude Code, tested with my own photos, released it
Built with
Django, Pillow, React, TipTap, Playwright
Status
In production since 4 November 2026

The problem

The carousel seemed to stop after two or three photos, as if it had a limit. It didn’t. Each photo was its own upload, and some were being turned away by the server with an HTTP 400.

The ones turned away had one thing in common: they were very large originals.

  • 10,687 by 6,011 pixels (64 megapixels)
  • 9,575 by 5,386 pixels (52 megapixels)
  • 12,000 by 6,752 pixels (81 megapixels)

The editor caught each failure and wrote it to the browser console, where no one writing a post would ever look. On screen, nothing happened.

Why it happened

Uploads go through a safety check that protects the server’s memory: no photo may decode to more than 8,000 pixels on a side or 36 million pixels in total.

A week earlier I had shipped automatic optimization, which shrinks every blog photo to at most 1,600 by 2,400 pixels before saving it. The JPEG library can do much of that shrinking while it decodes, so a huge photo never needs its full size in memory.

But the safety check ran first, against the original size. A photo the server could have shrunk safely was rejected for being too big to open at full size, before it ever reached the step that would shrink it.

Fixing that exposed a second limit. One photo was about 13 MB, over the 10 MB cap for inline images, so it was still refused. That cap was there to keep large uploads in check, and the original sizes were sensible for phone photos, not for originals from a camera.

The lines that decide

Before: the size is checked against the full picture, then the picture is shrunk.

with Image.open(io.BytesIO(content)) as image:
    # Check the original header first
    _enforce_policy(policy, len(content),
                    image.width, image.height)
    ...
    if actual_format == 'JPEG' and policy.photo_bounds:
        image.draft(image.mode, bounds)
    image.load()
Opening an uploaded image before, trimmed. Python.

After: the decoder is told to shrink first, and the same limits are checked against what will really be loaded.

with Image.open(io.BytesIO(content)) as image:
    ...
    if actual_format == 'JPEG' and policy.photo_bounds:
        image.draft(image.mode, bounds)
    # Bound what will be decoded, not the original
    _enforce_policy(policy, len(content),
                    image.width, image.height)
    image.load()
Opening an uploaded image now, trimmed. Python.

The limits themselves didn’t change. What changed is what they measure: the memory the server is about to use, not the size of the file on someone’s camera. Pillow’s own decompression-bomb check still runs before any of this.

And the editor now says what went wrong, per file:

} catch (err) {
  console.error('Carousel upload failed:', err);
}
The carousel before. JavaScript.
} catch (err) {
  const status = err.response?.status;
  const detail = err.response?.data?.error
    || err.response?.data?.detail
    || err.message || 'Upload failed.';
  const reason = status
    ? `HTTP ${status}: ${detail}`
    : `Upload failed: ${detail}`;
  failed.push(`${file.name}: ${reason}`);
}
// ...after the loop
setUploadErrors(failed);
The carousel now, trimmed. JavaScript.

Two releases, the same day

First, the check moved after the shrinking step, and the carousel learned to show errors. The same change fixed a quieter bug: deleting a photo while others were still uploading could bring it back, because finished uploads were added to an old copy of the list instead of the current one.

Then, camera originals up to 24 MB were allowed, for JPEGs only. PNG and WebP keep their old limits. Django was also told to write large uploads to a temporary file instead of holding them in memory, and to delete that file afterwards whether the upload worked or not.

24 MB was not a round guess. The web server in front already refused requests over 25 MB, and a test sends an exact 24 MB photo as a real upload to prove it still fits with room for the rest of the request.

Decisions and tradeoffs

Raise the limit, or shrink first
Simply raising the pixel limit would have let truly huge images use huge amounts of memory. Shrinking during decoding keeps the same memory ceiling and still accepts the photos.
Memory is still real
Measured locally, that 13 MB photo used about 194 MB of memory for under a second. Three at once used about 750 MB. The server has three workers and about 3.8 GB of memory, so this fits, but it is a local measurement, not a load test.
Only JPEGs got the bigger allowance
The decoder can shrink JPEGs cheaply while reading them. Other formats can’t, so they kept their limits.
Originals aren’t kept
Only the optimized copy is stored. That saves space and means the original can’t be recovered from the site.

How it was tested

Browser tests drive the real editor in Chromium, with the three photos that failed plus generated ones, through a real local Django server doing the WebP conversion. They cover five-photo batches, uploading one at a time, deleting during an upload, network and server failures, and the error messages shown.

As reported in the two pull requests, 4 November 2026
SuiteCoversResult
Image uploads, first release, backendLarge JPEGs, memory limits, decompression bombs, saving and reopening45 of 45 passed
Image uploads, first release, browserBatches, ordering, deletion mid-upload, failures shown8 of 8 passed
Image uploads, second release, backendSize limits, temporary files cleaned up, three uploads at once137 passed, 1 skipped
Image uploads, second release, browserThe same, plus a real 24 MB upload and error messages11 of 11 passed

The skipped test needs PostgreSQL, and that run used SQLite.

Outcome and limits

The photos that failed now upload, and when one can’t, the editor names the file and the reason. Both releases deployed on 4 November. Pillow still refuses some extremely large photos outright, which is the right answer for a server this size.

What I took from it: a safety check is only as good as what it measures. This one guarded memory, but it measured file dimensions, so it blocked work that was safe.

Next: Shrinking every photo automatically