LPS-42445 Close the input stream after checking the mime type to avoid "Too Many Files Open" errors
LPS-42445 Fix the compile error
LPS-42445 Put the error handling at one single place