The strategy by AcceptMime.properties fully depends on the mime-type (Content-Type) resolved from the file extension. It works like this:
It will be the rare case, but the user may try to upload the file with the invalid extension. For example, the user may try to upload the text file, whose file name is:
In this case, the MimeParser will resolve its mime-type as image/jpeg, and accept the uploaded file.
But, this is not what you want.
To prepare for this situation, MimeParser can check if the binary contents of the uploaded file match with the expected pattern for the specific mime-type (Content-Type).
After the mime-type (which is sent from the web browser) is found in AcceptMime.properties, MimeParser will inspect the binary contents of the uploaded file.
If the binary contents do not match with the expected pattern for the mime-type, MimeParser will throw CorruptedBinaryContentsException.
To check the binary contents for the specific mime-type, this Java API defines the very simple interface.
It is:
and has only one method.
There are so many mime-types in the world, and it is impossible to implement this interface for all the available mime-types.
Rather, the implementations for only the typical mime-types are included in this Java API.
They are:
| CheckBmpLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the BMP, there may be a case that the rest of the contents are invalid. |
| CheckGifLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the GIF, there may be a case that the rest of the contents are invalid. |
| CheckGifStrict | This class depends on Java ImageIO package, which is a part of JDK 1.4. Only if you use JDK 1.4 or later, you can use this class. |
| CheckJpegLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the JPEG, there may be a case that the rest of the contents are invalid. |
| CheckJpegStrict | This class depends on Java ImageIO package, which is a part of JDK 1.4. Only if you use JDK 1.4 or later, you can use this class. |
| CheckPngLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the PNG, there may be a case that the rest of the contents are invalid. |
| CheckPngStrict | This class depends on Java ImageIO package, which is a part of JDK 1.4. Only if you use JDK 1.4 or later, you can use this class. |
| CheckPdfLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the PDF, there may be a case that the rest of the contents are invalid. |
| CheckPdfStrict | This class depends on iText Java library. It is the FREE Java library for PDF. To use this class, please download it from: and place it under WEB-INF/lib directory. |
| CheckPsLight | This implementation checks only the first few bytes. Even if the first few bytes match the patterns for the PostScript, there may be a case that the rest of the contents are invalid. |
Note that all these implementations are packaged under:
To use these implementations, please edit BinaryCheckerDic.properties and list their fully qualified class names in it. It looks like this:
image/bmp=com.oopreserch.util.CheckBmpLight image/gif=com.oopreserch.util.CheckGifLight #image/gif=com.oopreserch.util.CheckGifStrict image/jpeg=com.oopreserch.util.CheckJpegLight image/pjpeg=com.oopreserch.util.CheckJpegLight #image/jpeg=com.oopreserch.util.CheckJpegStrict #image/pjpeg=com.oopreserch.util.CheckJpegStrict image/png=com.oopreserch.util.CheckPngLight #image/png=com.oopreserch.util.CheckPngStrict application/pdf=com.oopreserch.util.CheckPdfLight #application/pdf=com.oopreserch.util.CheckPdfStrict application/postscript=com.oopreserch.util.CheckPsLight |
Please place this property file under:
If the default implementations are not enough for you, you can implement your own ones and list their fully qualified class names to this property file. For details about:
interface, please read the API documentation (Java Doc) of this Java API.