• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

File validation after File Upload

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic