Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate a file extension

 
Mike Phillip
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Phillip
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic