JSP upload - detecting file type by mime type? what is application/octet-stream?

S

Stephen Riek

I'm uploading a file via servlets or JSP, using the O'Reilly
MultipartWrapper, and was hoping that to be able to determine the file
type (eg. Excel spreadsheet, Word document, Powerpoint, PDF) depending
on the Mime Type.

Simple enough using the O'Reilly servlet package ~

<%@ page import="com.oreilly.servlet.*" %>
<%
if (request instanceof MultipartWrapper) {
try {
// Cast the request to a MultipartWrapper
MultipartWrapper multi = (MultipartWrapper)request;
// The file upload field on the submitting form is called
'upfile'.
String mimeType = multi.getContentType("resourcefile");
...

%>

Strange thing though is that I'm not getting the expected Mime Type.
For example, I just uploaded a Microsoft Word document and the
mimeType String is "application/octet-stream" instead of the expected
"application/msword".

However, uploading Excel spreadsheets and PDF files provided the
expected results of "application/vnd.ms-excel" and "application/pdf".
(see http://www.bc.edu/bc_org/tvp/email/helpers.shtml or
http://www.yolinux.com/TUTORIALS/LinuxTutorialMimeTypesAndApplications.html
for lists of mime types)

So, does anybody know why the Microsoft Word documents send the wrong
mime type ? Should I instead just use the file extension to determine
file type perhaps ?

Thanks in advance,

Stephen
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top