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

Discussion in 'Java' started by Stephen Riek, Sep 19, 2003.

  1. Stephen Riek

    Stephen Riek Guest

    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
     
    Stephen Riek, Sep 19, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul J. Lay
    Replies:
    2
    Views:
    636
    Steven Cheng[MSFT]
    Apr 8, 2004
  2. CVerma
    Replies:
    2
    Views:
    10,260
    C Verma
    Sep 28, 2004
  3. CJ
    Replies:
    1
    Views:
    1,585
    Andrew Thompson
    Oct 29, 2004
  4. Jan Arickx
    Replies:
    0
    Views:
    207
    Jan Arickx
    Aug 25, 2003
  5. joe
    Replies:
    0
    Views:
    209
Loading...

Share This Page