'.Net Core - How to check if the uploaded IFormFile is really an Image not relying on extension/mime type

When I upload a file from my React application to my server .NET Core api, I'm expecting a IFormFile type which should be an image. I'm validating the extension/mime type, but if the user changes, for example, an executable extension from 'executable.exe' to 'executable.png' it will pass through the validation! I searched a lot looking for a solution, I couldn't find any answer that suits my needs, I will keep looking, but meanwhile if someone already solved this kind of issues please let me know the better way to handle with this validation, avoiding answers that rely on getting the file extension whether the mime type.

Thanks all that can help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source