Hi Dan,

I'm using a separate validator for filesize:

public void validate(IFormComponent field, ValidationMessages messages,
Object object) throws ValidatorException 
{
        IUploadFile file = (IUploadFile)object;
        if (file.getSize() > maxSize)
        {
                throw new ValidatorException("File size exceeds
limit.");
        }
}

If the MultipartDecoderImpl maxSize gets hit, I think the exception gets
thrown directly from the servlet container or something (based on the
way the error looks.. I could be wrong.) So I think its more a matter of
validating below that limit, whatever it is.

Ben

-----Original Message-----
From: Daniel M Garland [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 15, 2005 11:18 AM
To: Tapestry users
Subject: Re: Client-side validated uploads

Hi Ben,

Where do you catch the exception that is thrown when you exceed the
limit?

Thanks
Dan

Ben Dotte wrote:
> Actually I believe file uploads have a hard-coded limit of 10mb right
> now so I doubt that would be a problem (I've seen this limit hit, you
> get a big ugly error message). See
> http://issues.apache.org/jira/browse/TAPESTRY-764
> 
> To get rid of the nasty error message when this limit is hit, I
believe
> its not hard to validate the filesize to be below the 10mb limit..
can't
> remember the details off the top of my head. You can also override
> MultipartDecoderImpl and make a public setter on maxSize if 10mb is
too
> small.
> 
> Ben
> 
> -----Original Message-----
> From: Daniel M Garland [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 13, 2005 11:07 AM
> To: Tapestry users
> Subject: Re: Client-side validated uploads
> 
> Hi Ben, all
> 
> This is also close to what I had come up with. Actually, I had to
avoid 
> the use of ImageIO because we're deploying on Mac OSX and their
ImageIO 
> is buggy im sure...
> 
> Anyway, this server-side solution has the following problems:
> 1) If you try to upload a 1GB file, you arn't stopping anybody
> 2) You're reading all that data into memory, again if you upload the 
> huge file then you're going to lead to issues
> 
> In my case, we're hoping that some non-I.T. people will be using the
app
> 
> and I can garantee they'll try to upload a billboard-sized TIFF. Hence

> the need to validate client-side.
> 
> It would be nice if I could set the value field on a file type (which
is
> 
> what is allowed in the 4.01 spec) but it is not supported in most
> browsers.
> 
> Do I have to actually implement my own uploading code? Ouch :(
> 
> Ben Dotte wrote:
> 
>>I wrote a validator for this but I'm not totally sure this doesn't end
>>up uploading the whole file anyway.. doesn't seem like it though.
>>
>>public void validate(IFormComponent field, ValidationMessages
> 
> messages,
> 
>>Object object) throws ValidatorException 
>>{
>>      IUploadFile imageFile = (IUploadFile)object;
>>      InputStream fis = imageFile.getStream();
>>      ImageInputStream iis = null;
>>
>>      try 
>>      {
>>              iis = ImageIO.createImageInputStream(fis);
>>              Iterator imageReaders = ImageIO.getImageReaders(iis);
>>              if (!imageReaders.hasNext())
>>              {
>>                      // There are no image readers for this file
>>                      fis.close();
>>                      throw new ValidatorException("Invalid image
>>file.");
>>              }
>>              ImageReader firstReader =
>>(ImageReader)imageReaders.next();
>>              String imageFormat =
>>firstReader.getFormatName().toLowerCase();
>>              if (!imageFormat.equals("jpeg") &&
>>!imageFormat.equals("jpg") &&
>>                      !imageFormat.equals("gif") &&
>>!imageFormat.equals("png"))
>>              {
>>                      // This is a valid image but we only accept
>>jpeg, jpg, gif, or png
>>                      fis.close();
>>                      throw new ValidatorException("The image format
>>must be JPG, GIF, or PNG.");
>>              }
>>              BufferedImage image = ImageIO.read(iis);
>>              if (image.getWidth() > maxWidth || image.getHeight() >
>>maxHeight)
>>              {
>>                      // This image is too big
>>                      fis.close();
>>                      throw new ValidatorException("The image exceeds
>>the maximum width/height.");
>>              }
>>              fis.close();
>>      } 
>>      catch (IOException ioe) 
>>      {
>>              // There was some other problem uploading the image
>>              throw new ValidatorException("Invalid image file.");
>>      }
>>      finally 
>>      {
>>              if (iis != null) {
>>                      try { iis.close(); } catch (IOException ioe) {}
>>              }
>>              if (fis != null) {
>>                      try { fis.close(); } catch (IOException ioe) {}
>>              }
>>      }
>>}
>>
>>HTH
>>
>>Ben
>>
>>-----Original Message-----
>>From: Daniel M Garland [mailto:[EMAIL PROTECTED] 
>>Sent: Tuesday, December 13, 2005 10:01 AM
>>To: [email protected]
>>Subject: Client-side validated uploads
>>
>>Hi all,
>>
>>I'm trying to figure out how to get around a brick wall:
>>
>>I want to validate an image file based upon its dimensions and
> 
> filesize 
> 
>>before allowing the file to be written up to the server. I thought
> 
> about
> 
>>achieving this using a signed applet to read the file, and then pass
> 
> an 
> 
>>acceptable filename to an Upload component. However, the value field 
>>will not be supported in most browsers, so is there any other way I
> 
> can 
> 
>>use the Uploading features of Tapestry by somehow extending Upload?
>>
>>If not, where is the code that does this? I hear something about the 
>>commons project at apache but currently jakarta.apache.org/commons/ 
>>appears to be down.
>>
>>Thanks for your help in advance.
> 
> 

-- 
Dan Garland
------------------------
[EMAIL PROTECTED]
mob: +44 (0) 7979 770053
icq: 120963437
aim: dmgarland1767


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

---------------------------------------------------------------------
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]

Reply via email to