Module 45: Files and Logging

Lesson 3 of 5 · 15–25 minutes

Validating uploads

🏠The everyday picture

A bank teller doesn't accept a cheque just because it's labelled "cheque". They check the paper, the signature and the amount.

📘What it really is

🖱️Try it

Add file-type to your upload route. Accept only PDF, JPEG and PNG, checked by content. Test by renaming a .txt file to .pdf and uploading it: it should be refused with a clear message. Make the download route send Content-Disposition: attachment.

✅Quick check

A file is named photo.jpg and the browser says image/jpeg. Is it safe to trust that it's a JPEG?

Show the answer

No. Both can be faked; check the file's actual content.

Why can accepting SVG or HTML uploads be dangerous?

Show the answer

They can contain scripts that run in visitors' browsers if served from your site.

← PreviousFile uploads
ProLearners Assist