How can I check if the file uploaded on my server is really an image? Not just a file with (jpg,png,gif) extension just to make it as "an image" file. I created an image compression service using imagemin, but I'm afraid if the uploaded file is really an image.
// node backend schema validation const Joi = require("joi-browser"); Joi. image = require("joi-image-extension"); const image = new mongoose. Schema({ image: { type: String, required: true, }, }) // validation function function validateEmployee(employee) { const schema = { image: Joi. image().
I have used the mmmagic module for this, it discovers mime types: mmmagic on Github
Another option is https://github.com/sindresorhus/image-type. Looks like mmmagic relies on libmagic which is a C lib and might be a lot to pull in...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With