Hi,
Thanks for the reply.
But I have a doubt, what if user manually changes extension of some other
file type (e.g. .bmp file) to .tdt/.txt type
and uploads that file? In that case though the extension is correct,
contents of the file are not?

Thanks and Regards,
Abhijeet.


On 4/28/06, Paul Copeland <[EMAIL PROTECTED]> wrote:

Create a javax.activation.MimetypesFileTypeMap object and add your types
to that object. Then call
javax.activation.MimetypesFileTypeMap.getContentType(yourFileName) to
get the contentType for the file on the server without relying on the
browser content type setting.   MimetypesFileTypeMap will return
application/octet-stream as the default if it does not know the content
type. You have to include the J2EE activation.jar in your classpath for
this to work.  Here is the API doc -


http://java.sun.com/javaee/5/docs/api/javax/activation/MimetypesFileTypeMap.html

Paul Copeland
http://www.jotobjects.com
JOT Servlets dynamic web component framework


>Date:    Fri, 28 Apr 2006 10:09:54 +0530
>From:    Abhijeet Kahale <[EMAIL PROTECTED]>
>Subject: Problem with Struts FormFile object.
>
>Hi,
>
>I am facing some problems while uploading a file using Struts' FormFile
>object.
>I want to allow user to upload only .xls/.tdt/.txt files. For that I am
>comparing the ContentType of the file being uploaded using FormFile's
>getContentType() method.
>The problem is, when I upload .xls files, it properly returns a string as
>'application/vnd.ms-excel' so that i can compare it with constant and
>proceed further.
>But when I upload .tdt or .txt files, it returns a string
>'application/octet-stream' instead of 'text/plain', So when i compare it
>with the constant(which is set to "text/plain"), test fails even if user
ha=
>s
>uploaded proper file with proper contents.
>Moreover, this only happens on my machine, If I test it on some-one else'
>machine(one of my colleague), it works fine.
>So, my question is, is there some setting in my browser that is making
the
>formfile object to send wrong mime type or this is really a problem? And
if
>it is related to browser setting, what setting should I change? also, if
>user also has that setting in his browser, how should I handle it?
>
>please reply ASAP...
>
>thanks in advance,
>Abhijeet.
>
>


===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com


===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com

Reply via email to