DEV Community

Arham_Q
Arham_Q

Posted on

Devlog #2 — I Hate PDFs: Why I Never Save Uploaded Files to Disk

If you missed Devlog #1, I built an AI-powered Quiz & Flashcard generator that turns any PDF into a quiz using Groq AI. This is what came next.

A Decision Before Writing a Single Line
When I started wiring up the file upload logic for I Hate PDFs my student-focused PDF toolkit.I had an obvious plan:
User uploads PDF → save it to disk → do the operation → return the result.

Simple. Familiar. What most tutorials show.
But before I actually wrote that code, I paused and researched a bit. The questions I had were straightforward, what happens when two users upload at the same time? Who cleans up the saved files? What if I deploy this on a server with limited storage?
That research led me to something I hadn't used before: Python's BytesIO.

What Even Is BytesIO?
BytesIO lives in Python's built-in io module. The simplest way to think about it.It's a file that exists only in memory.
It behaves exactly like a real file. You can read from it, write to it, pass it around, but it never touches your disk. The moment it's no longer needed, Python clears it automatically.
pythonfrom io import BytesIO

sample code

How I Use It in I Hate PDFs
Almost every feature in this project involves a user uploading a PDF merge, split, compress, extract text. BytesIO handles all of it without ever writing to disk.

Text extraction for the Quiz Generator:
code about operation on RAM

The uploaded PDF goes straight into a BytesIO buffer, gets passed to PyMuPDF's fitz, and the text comes out no file ever saved.
Sending a processed PDF back to the user:

last wrap-up

What's Next
The core operations and core features are coming together. Next, I’ll focus on refining the user interface and ensuring the tool is shareable, stay tuned for a live demo soon.
If you're developing an application with file uploads in Flask or any Python backend, consider using BytesIO instead of saving files to disk. This small choice can significantly enhance the cleanliness of your code from the outset.

I Hate PDFs is still evolving, building in public.
building in public. Follow along for Devlog #3.

Top comments (0)