• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: WOFileUpload
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WOFileUpload


  • Subject: Re: WOFileUpload
  • From: Asa Hardcastle <email@hidden>
  • Date: Fri, 18 Apr 2008 23:01:43 -0400

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@hidden)
Help/Unsubscribe/Update your Subscription:
@zenn.net


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >WOFileUpload (From: "sirius black" <email@hidden>)

  • Prev by Date: Re: WOFileUpload
  • Next by Date: Re: ERXMutableArray fields in Entity Modeler
  • Previous by thread: Re: WOFileUpload
  • Next by thread: Re: WOFileUpload
  • Index(es):
    • Date
    • Thread