PS - there was a discussion recently on how to improve the 
Validator.

Validating an uploaded file based on mime type would be cool !

A quick search on the web led me to a company that does this 
With a java api

http://www.oop-reserch.com/mime_prop.html

It seems in jdk1.4 you can actually validate based on the 
binary pattern expected for a mime type. So if it is a gif, 
you can check that the bit pattern of the uploaded file 
matches that of a gif.

This is apparently to avoid users uploading say a text file
named mytextfile.gif

Now that would be nice :-)
Brian


-----Original Message-----
From: Brian McSweeney [mailto:[EMAIL PROTECTED] 
Sent: 22 August 2003 11:13
To: 'Struts Users Mailing List'
Subject: Validating uploaded file as an image only

Hi everyone,
 
I've managed to get the struts file upload working successfully, 
using the struts FormFile class and the upload example.
 
Cool :-)
 
However, in my app, I only want images to be uploaded.
I'm going to store the images on disk and put the path of the 
image file into the database. So I need to validate that only images
are getting uploaded, not other file-types.
 
I know nothing really about how to do this. I could just check that 
string returned by:
 
FormFile.getContentType( ) 
 
is equal to image-gif, image-bnp, or image-jpeg. But is this enough?
 
 
Also, I have noticed that when I upload an image file and the little 
Browser window pops up, if I select a gif image, but the file type 
bar says "All files" then the file isn't recognized as an image.
It's recognized as an octet-stream. So does the browser window 
specify the file type to the browser?
 
Anyway,
 
Hope someone can give me some advice,
As always,
Thanks very much,
Brian


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to