aspose file tools*
The moose likes Java in General and the fly likes validate a file extension Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "validate a file extension" Watch "validate a file extension" New topic
Author

validate a file extension

Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
Hi, I doing a server that upload and saves files, it's working fine.

But, I need to let only some extension (like txt and jpg), I'm using the file extension, if it's different I refuse, but a user can rename the file extension before the upload and bypass it.

I found a software called JMimeMagic, it's good, but works with most of thw files, but some time doesn't validate some real txt.

works like this:



any good solution/software for that?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39568
    
  27
I'm not sure how JMimeMagic works, but if it's image formats you need to deal with, have a look at the ImageInfo class. It identifies a number of image formats based on the contents, not on the name or MIME type.


Ping & DNS - updated with new look and Ping home screen widget
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
thanks for reply.

Well, it's most image and text. With images the JMimemagic is great, the problem is with txt, some times it fails.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

How does it fail?
Accept a file as txt which isn't?
Deny a file, which is a txt-file?

How is it identified, if not as txt?


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validate a file extension
 
Similar Threads
how do I take out the extension in javascript :( urgent ....
Making a Read-Only File Writeable
Can i check i byte[] contains binary bytes ???
How to make sure a file is a valid text file.
Determine file (image) type from an InputStream