The content upload nightmare

How to properly detect the content of a file

Vincent Dufrasnes
Aug 17, 2020 · 8 min read

“What is this file?”

This is a simple question I didn’t care much about. But that was before I had to properly handle file uploading.

This question is easy, anyone can answer it quickly. test.pdf is a pdf, it ends with pdf, image.jpg is a jpg , and that's when things start to get interesting, because there are a lot of questions you can ask to make someone doubt:

  • Are you sure it’s a pdf? Someone could have changed the…