Handling requests safely · mid
File uploads: multer and presigned URLs
For uploads, either parse multipart/form-data with multer and strict limits, or better, let the client upload straight to object storage (S3) with a short-lived presigned URL so large files never pass through your Node server.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- multipart/form-data is not parsed by express.json. multer (2.x current) handles it: memoryStorage keeps the file in RAM (small files only), diskStorage writes to disk. Always set limits (fileSize, files) and a fileFilter.
- Do not trust the file name or the client's mimetype. Generate your own name/key, check the file's magic bytes if the type matters, store outside the web root, scan if needed.
- Large files through the API cost memory, bandwidth and time, and cannot easily resume.
- Presigned flow: client asks POST /uploads -> server checks auth, picks the key, returns a presigned PUT URL (or a POST policy that can enforce a size range) valid for minutes -> client uploads directly to S3 -> client (or an S3 event) tells the server it finished -> server validates and processes (thumbnails in a background job).
- Private downloads: presigned GET URLs or CloudFront signed URLs, never a public bucket.
- A presigned URL made with temporary credentials (an IAM role) stops working when those credentials expire, even if you asked for longer.
The red pen
Common traps: mistake → fix
Mistake: express.json() handles uploads
Fix: multipart needs multer or busboy.
Mistake: Checking the file extension is enough
Fix: the extension and Content-Type come from the client.
Mistake: A presigned URL lets anyone upload anything
Fix: you choose the key and expiry, and a POST policy can limit the size and type.
Easy to hard
Questions interviewers ask, easy to hard
- How do you handle file uploads in Node?
- Why not send a 500 MB video through your API server?
- Explain a presigned-URL upload end to end.
- How do you make sure users only upload images under 5 MB?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.