• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find image file extension from byte array?  RSS feed

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I stored image as byte array into the database succesfully.

After that i want to show that image in my page. So i can get the byte array from the database.

Is possible to find the (image)file extension from that byte array.(png, jpeg, gif etc...)

please help me.

Thanks in advance.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if that is possible but why don't just just also store the mime-type in the database?
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. In one scenario I had done exactly that.
I had a custom object with file name, mime type and byte[] data as variables.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For most image formats it should be possible to read the type from the first few bytes, but I still would store the image mime type or extension in the database instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!