Getting A File's Mime Type In Java

后端 未结 23 2756
南方客
南方客 2020-11-21 06:53

I was just wondering how most people fetch a mime type from a file in Java? So far I\'ve tried two utils: JMimeMagic & Mime-Util.

Th

23条回答
  •  逝去的感伤
    2020-11-21 07:35

    It is better to use two layer validation for files upload.

    First you can check for the mimeType and validate it.

    Second you should look to convert the first 4 bytes of your file to hexadecimal and then compare it with the magic numbers. Then it will be a really secure way to check for file validations.

提交回复
热议问题