Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to identify the file format from byte array?

 
Kishore Polsani
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have a web service which reads any file format and returns a byte array. In client side I need to read that byte array and open the file. How can we identify the file format from that byte array???

Thanks in advance
Kishore
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to provide some content-type information along with the contents?
 
Kishore Polsani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,
Thanks for reply. Can you please tell me how we can achieve this or please provide some code snippet for this.
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> i have a web service which reads any file format and returns a byte array

The Web service could provide besides the contents also the content type.
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is by the way no such thing as "the content type" of a file per se.
There exists a funny file format: a portion of C code with data which can also be considered as an image. Is such a file a piece of plain text, C source, C++ source or an image file?

There exists the file naming convention that the last portion of a file's name (the one after the dot - also called "extension") hints on the content.
Web servers can be configured how to map these "extensions" to content-types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic