Hi Adam, Cool! I had no clue that any of this was available. A few questions if you don't mind.
What is the purpose of using the MediaTracker? I understand how using Image makeimg = Toolkit.getDefaultToolkit().createImage( image.getFileData() ); will show you if it's a proper image, but I don't understand how the MediaTracker class helps? Does it just show if the image could be re-displayed or something? If that assumption is correct, then the javadocs say that: "If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny and isErrorID methods to check for errors. " So should you perhaps use these "isErrorAny" or "isErrorID" methods too? Any problems ever experienced? Anyway, really appreciate this help, Brian -----Original Message----- From: Adam L [mailto:[EMAIL PROTECTED] Sent: 22 August 2003 13:12 To: Struts Users Mailing List Subject: Re: Validating uploaded file as an image only I do it the brute force way: <---- snip ---------> FormFile image; .... java.awt.Image makeimg = null; try { makeimg = Toolkit.getDefaultToolkit().createImage( image.getFileData() ); // wait for the image to be loaded/created Canvas cv = new Canvas(); MediaTracker media_tracker = new MediaTracker( cv ); // add image to the tracker int id = 0; media_tracker.addImage(makeimg,id); // try to wait for image to be loaded // catch if loading was interrupted media_tracker.waitForID(id); // if we can't load it, it'll get tossed back from the catch() // by now we should have a good image to deal with // check on image dimensions int imgw = makeimg.getWidth( cv ); int imgh = makeimg.getHeight( cv ); } catch (......) <----------------end snip----------> I also check for file size (ie, dont' allow anything over 1M), and then image dimensions. The only thing I don't do is validate the mime-type. I haven't tried uploading images from a text browser (ie lynx or links), yet, to see what sort of mime-type it would attach.. but the ones from IE always seem to be fine. cheers! -- adam ----- Original Message ----- From: "Brian McSweeney" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Friday, August 22, 2003 6:32 AM Subject: RE: Validating uploaded file as an image only > 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] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]