How to extract file extension from byte array

前端 未结 3 1203
你的背包
你的背包 2020-12-05 05:17

I\'ve got bytes array in database.

How to extract file extension (mime/type) from byte array in java?

3条回答
  •  长情又很酷
    2020-12-05 05:26

    Maybe I need to save additional column in my DB for file extension.

    That is a better solution than attempting to deduce a mimetype based on the database content, for (at least) the following reasons:

    • If you have a mime type from the document source, you can store and use that.
    • You could (potentially) ask the user to specify a mimetype when they lodge the document.
    • If you have to use some heuristic-based scheme for figuring out a mimetype:
      • you can do the work once before creating the table row, rather than N times after extracting it, and
      • you can report cases where the heuristic gives no good answer, and maybe ask the user to say what the file type really is.

    (I'm making some assumptions that may not be warranted, but the question doesn't give any clues on how the larger system is intended to work.)

提交回复
热议问题