Saturday, 14 September 2013

HTTP response content type

HTTP response content type

I am implementing a file download feature via a servlet and tried using
Files.probeContentType without success, it doesn't seem to pick up the
right MIME type, so I use a default of application/octet-stream when that
happens. In my testing, that setting seems to work ok with all the various
file types like tar, gif, gz, mp4, xml, json, work as in the files are
downloaded correctly and can be opened with their respective apps.
First question, if anyone can tell me what I am doing wrong with
probeContentType or a better way to determine the mime type, that'll be
most appreciated, here are the few lines of code in Scala
val is = new FileInputStream(file)
val mt = Files.probeContentType(file.toPath)
val mimetype = if (mt == null) "application/octet-stream" else mt
Regardless, is it ok to always set the HTTP response content-type to
application/octet-stream? I have only tested with Chrome and Firefox.

No comments:

Post a Comment