Content type of image

V

Vikram

Hi,
I have the binary representation of an image ( byte[] ). Can I
get the content type in the form "image/xxx" from it ?
 
J

Jeff Higgins

Vikram said:
Hi,
I have the binary representation of an image ( byte[] ). Can I
get the content type in the form "image/xxx" from it ?

It's not clear to me what you are asking. I can think of
several interpretations of your question. So for now the
short answer has to be; yes, and the long answer; no.
 
A

Andreas Leitgeb

Jeff Higgins said:
Vikram said:
I have the binary representation of an image ( byte[] ). Can I
get the content type in the form "image/xxx" from it ?

It's not clear to me what you are asking. I can think of
several interpretations of your question. So for now the
short answer has to be; yes, and the long answer; no.

I think it's quite clear, that the OP wants the mime-type
for an image that is stored in a byte-array.

On linux (or other systems with GNU-file installed), he could
feed the byte-array as input to the system command "file -bi -"
and read back the result.

Probably there exist easier or more platform-neural ways to
do it, but I don't know them, either.

Anyway, there is no 100% sure way of knowing. Type-recognition
by content is somewhat safer than by filename-extension, but
still has it's error-cases. (mostly false positives, where a
filetype is detected, for which the byte-array doesn't contain
legal data)
 
J

Jeff Higgins

Andreas said:
Jeff Higgins said:
Vikram said:
I have the binary representation of an image ( byte[] ). Can I
get the content type in the form "image/xxx" from it ?

It's not clear to me what you are asking. I can think of
several interpretations of your question. So for now the
short answer has to be; yes, and the long answer; no.

I think it's quite clear, that the OP wants the mime-type
for an image that is stored in a byte-array.

If indeed this is the OP's question then in addition to the suggestions
you present Real's How To makes some suggestions at this web page:

<http://www.rgagnon.com/javadetails/java-0487.html>

and a fruitful web search phrase might be "mime-type recognition" java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top