File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
validate a file extension
Joined: Dec 05, 2007
Dec 17, 2007 13:18:00
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:
// snippet for JMimeMagic lib // <a href="http://sourceforge.net/projects/jmimemagic/" target="_blank" rel="nofollow">http://sourceforge.net/projects/jmimemagic/</a> Magic parser = new Magic() ; // getMagicMatch accepts Files or byte, // which is nice if you want to test streams MagicMatch match = parser.getMagicMatch(new File("gumby.gif")); System.out.println(match.getMimeType()) ;
any good solution/software for that?
Joined: Mar 22, 2005
Dec 17, 2007 14:23:00
I'm not sure how JMimeMagic works, but if it's image formats you need to deal with, have a look at the
. It identifies a number of image formats based on the contents, not on the name or MIME type.
Ping & DNS
- my free Android networking tools app
Joined: Dec 05, 2007
Dec 17, 2007 15:12:00
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.
Joined: Jun 02, 2003
Dec 18, 2007 20:19:00
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?
Don't get me started about those stupid
subject: validate a file extension
How to make sure a file is a valid text file.
Can i check i byte contains binary bytes ???
Making a Read-Only File Writeable
Determine file (image) type from an InputStream
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014