File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File validation after File Upload

 
Sunetra Sen
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am supposed to upload a file which should be of type csv.
Now after I upload the file from my jsp I am using the jakrta file upload utility to write it to some specified folder.
But the functionality requuires me to verify that the file is truly a csv file before I write it to the specified directory.
Can anyone suggest how I can validate the type of a uploaded file to be csv?

Thanks in advance,
Sunetra.
 
Johannes Postma
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know the Java API doesn't have a standard method for validating a csv file. You must implement this validation by yourself.
 
Sunetra Sen
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah the java API doesn't give any validation for csv files.
For Netscape/Firefox/IE the file content type for a csv file comes as application/octet-stream.
I am validating that the file uploaded by the user has this type and extension csv.
However as you might have guessed that if I intentinally save a bitmap file with a csv extention then also this validation succeeds.
So this is a *poor* way to validate csv files.
Any ideas on how this validation can be done in a better way?

thanks and regards,
Sunetra.
 
Johannes Postma
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunetra,

I think you have to implement the csv specification by yourself. You can find the specification on the next url:

http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm#FileFormat

If the file doesn't meet the specification the file is invalid.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic