Beginner · About 10 minutes · Reliable applications
Your File Is Too Large.
Maya's résumé is 8 MB. The website allows 5 MB. How should the upload work?
Answers stay in this browser until you save them on this device.
What happened?
Maya applies for a job and uploads her résumé.
The website accepts PDF files up to 5 MB. Maya chooses an 8 MB PDF, but the website says “Upload complete.”
Later, the recruiter cannot open her résumé. You investigate and find that the website showed success before confirming that the file was accepted and saved.
1. Choose an 8 MB file
Maya selects maya-resume.pdf.
8 MB PDF
maya-resume.pdf
2. Website incorrectly says Upload complete
Success appears before the file is validated and saved.
Website message
Upload complete
3. Recruiter cannot use the uploaded file
The résumé was never properly accepted.
Recruiter view
Cannot open résumé
Try an example
Illustrated example—not a live upload
Fictional file
maya-resume.pdf
8,000,000 bytes
Too large — reject before saving. Message: Your file is too large. Choose a PDF that is 5 MB or smaller.
Your task
How would you reject files that do not meet the rules and show “Upload complete” only when the file has been saved successfully?
Visible rules
- One PDF at a time.
- The file must have at least one page and must not be password-protected.
- The limit is 5 MB. Here, 5 MB means 5,000,000 bytes. A file exactly that size is allowed.
- You do not need to write code for the first three questions.
Related path: System Design Interview Sprint
Interview answer
Explain it in an interview
Maya uploaded an 8 MB resume to a site that allows 5 MB, and the page said the upload was complete. How should success be decided?
Maya applied for a job and uploaded an 8 MB PDF resume. The site accepts files from 1 byte through 5,000,000 bytes. The page said the upload was complete, but the recruiter could not open a usable file. Success was shown before the upload was validated and saved.
Step 1
Success came before the file was real
The handler accepted Maya's upload and reported success while the 8 MB PDF was still unchecked. The recruiter later had nothing usable, because the file was never validated and never committed as a saved resume. The bug is the moment success is spoken. An 8 MB resume is already outside the 5,000,000 byte cap.
Step 2
A declared size is not the file
Trusting the browser's declared length, or a name that ends in pdf, lets a bad body through. Showing success as soon as the bytes arrive repeats the same bug. I have to read the actual bytes, measure them, and reject this resume before any success response. The check has to see the file, not the form's promise.
Step 3
Validate the whole file first
I check the filename, the declared type, the real size, a PDF header, a parser-readable structure, the encryption flag, and at least one accessible page. Anything outside 1 to 5,000,000 bytes fails, so Maya's 8 MB resume never becomes a saved file. A rejection only means the file is outside the subset this lab accepts.
Step 4
Commit the row after the save
A file that passes is written under a temporary name, renamed into place, and then recorded in the database. I return success only after that insert commits. Ordinary caught failures try to remove the new file. I do not tell the recruiter the upload finished before that commit.
Step 5
A crash can leave an orphan file
The filesystem and the database are not one transaction. If the process dies after the rename and before the commit, an orphan file or a missing row can remain. This lab does not scan for orphans and it does not retry automatically. A repeated upload of a valid small PDF creates another record, because duplicate detection is out of scope.
Step 6
Do not claim the file is safe
Passing these checks does not prove every PDF stream will render, or that embedded content is safe. There is no malware scan, no login, and no public file access. I would not expose this single-process server or feed it hostile files. Strict parsing is a teaching gate, not a certificate.
Do not stop here
I would show upload complete as soon as the browser finishes sending, and I would enforce the 5 MB limit from the declared size.
Say this boundary
I refuse Maya's 8 MB resume during validation, and I report success only after a file that passed every check is committed.
Leave these claims out
- The parser proves every PDF is valid
- The file and the database commit together
- This upload is safe to expose publicly
I would walk from the 8 MB rejection through the temporary file, the rename, and the commit. Success means the saved resume passed this lab's checks, and nothing broader.
Now say the same idea in your own words, using the story from this challenge.