How to properly detect the content of a file

“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:

Vincent Dufrasnes

Back-end developper specialized in NodeJs. Fan of Clean Architecture

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store