aspose file tools*
The moose likes Java in General and the fly likes File validation after File Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "File validation after File Upload" Watch "File validation after File Upload" New topic
Author

File validation after File Upload

Sunetra Sen
Ranch Hand

Joined: Feb 17, 2005
Posts: 43
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

Joined: Jan 22, 2002
Posts: 51
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.


Johannes<br /> <br />SCJP, SCJD, SCWCD, SCDJWS, SCEA, ICSA (IBM 340)
Sunetra Sen
Ranch Hand

Joined: Feb 17, 2005
Posts: 43
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

Joined: Jan 22, 2002
Posts: 51
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
 
subject: File validation after File Upload