I like the idea of this approach, but maybe I'm not understanding you
completely.  If I change my html to not use WOFileUpload and instead just
upload like a normal file-upload:

Browse file:

<input name="fileName" type="file">

<br><webobject name="SubmitButton"/>
-------------------------------------------------------------------

SubmitButton: WOSubmitButton {

  action = submit;

  value = "Upload File";

}


Then it seems like I'm still reading in all the data before I even get to
my takeValuesFromRequest. In fact when I get to larger files (~ 500MB ->
1.0GB) I don't even get to the takeValuesFromRequest and something else goes
wonky.

Is this how you meant to implement this?  Or am I missing another
web-objecty way to grab the file name information.

Thanks,

On Fri, Apr 18, 2008 at 7:55 PM, Asa Hardcastle <[EMAIL PROTECTED]> wrote:

> Hi Sirius,
>
> This approach does not solve reading _any_ data from the wire, but it will
> cut the user short if a limit is exceeded; use WOMultipartIterator instead
> of a WOFileUpload.
>
> (In takeValuesFromRequest or inside of a direct action, )
>
> first check the header and dump out if it is too big (although it does not
> give much insight if you have multiple files):
> request.headerForKey("content-length")
>
> ... and if the header is lying!!!!! That dirty rascal!!
>
>  grab the multipart iterator
>
>  WOMultipartIterator multipartIterator = request.multipartIterator();
>
> Loop through the formdata calling multipartIterator.nextFormData()
>
>  WOMultipartIterator.WOFormData formData =
> multipartIterator.nextFormData();
>
> Test for a file input:
>
>  formData.isFileUpload()
>
> If it is a file upload, grab the name and the stream
>
>  formData.name()
>  InputStream in = formData.formDataInputStream()
>
> Now write the stream to disk manually, reading into a buffer and writing
> to an output stream, keeping track of how many bytes you have written and
> dumping out if you exceed the limit.
>
> Something like this should work:
>
> byte[] buff = new byte[25600];
> int b_total = 0, b_read = in.read(buff);
> OutputStream out = new FileOutputStream("/tmp/maybearealybigfile");
> while(-1 != b_read)
> {
>   b_total += b_read;
>   if(b_total > MY_MAX_BYTES)
>   {
>       ... close output stream and delete the partial file from disk ...
>       break;
>   }
>   out.write(buff, 0, b_read);
>   b_read = in.read(buff);
> }
> ... close your streams if they are open ...
>
>
>
> http://developer.apple.com/documentation/DeveloperTools/Reference/WO541Reference/com/webobjects/appserver/WOMultipartIterator.html
>
>
>
> hope this helps,
>
> :)
>
> asa
>
>
>
>
>
> On Apr 18, 2008, at 8:10 PM, sirius black wrote:
>
> > I'm trying to verify the size of a file upload and limit its upload
> > before actually sending any data across the wire.  I know I can check the
> > content-length header early on in the game in dispatchRequest, but even if I
> > just throw a RuntimeException at that point, I can't stop WebObjects from
> > reading in the data anyways, before sending back a response.  I'm using
> > WOFileUpload with streamToFilePath.
> >
> > Fwiw, I've looked into javascript validation to try and check the
> > content-length client side first, but haven't had success with that.
> >
> > Thoughts?
> >
> > _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Webobjects-dev mailing list      ([email protected])
> > Help/Unsubscribe/Update your Subscription:
> > http://lists.apple.com/mailman/options/webobjects-dev/a.talk%40zenn.net
> >
> > This email sent to [EMAIL PROTECTED]
> >
>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to