Java get image extension from byte array

后端 未结 2 520
醉话见心
醉话见心 2021-01-05 06:50

I have the below code for saving an image from a byte array.

I am able to save the image successfully using the below code.

Currently I am saving image with

2条回答
  •  囚心锁ツ
    2021-01-05 06:58

    There are many solutions. Very simple for example:

    String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(imageBytes));
    

    Or you can use third-party libraries. Like Apache Tika:

    String contentType = new Tika().detect(imageBytes);
    

提交回复
热议问题