aspose file tools*
The moose likes Other Open Source Projects and the fly likes Apache Fileupload via Stream. Possible to cancel the upload? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache Fileupload via Stream. Possible to cancel the upload?" Watch "Apache Fileupload via Stream. Possible to cancel the upload?" New topic
Author

Apache Fileupload via Stream. Possible to cancel the upload?

Gray Mann
Greenhorn

Joined: Dec 23, 2009
Posts: 2
Hi,

I'm using the Apache FileUpload lib to deal with file uploads. It generally works fine however Ive come across an annoying bug.

A user can upload a zip file, the code that obtains the ref to the stream is this:



It goes on to deal with the stream. I read the bytes from itemStream, checking the total number of bytes I've read each time. If the total number of bytes read exceeds a MAX_FILE_SIZE limit I throw an exception and deal with it.

This is the issue:

When I call itemStream.close() the code seems to wait at this point while the browser continues to upload the file, when the upload is done the itemStream.close() returns and the code carries on.

What I would have expected is itemStream.close() to terminate the stream's connection immediately, I know the file size is already too big, so I don't want to waste time/bandwidth waiting for the rest of it to upload before I can display an appropriate message to the user.

Imagine for some reason the user tries to upload a 50Gb file, when the limit is 10Mb, they'd have to wait until 50Gb were streamed before the error response was displayed to the user!!

Any ideas how to abort a file upload??
Gray Mann
Greenhorn

Joined: Dec 23, 2009
Posts: 2
I removed the itemStream.close() just to see what would happen, the browser continues to upload the file.

I can't seem to find anything that suggests it possible to abort the fileupload once the request from the browser has been sent.

Should not that I can't do anything like a dodgy workaround like refreshing the browser etc for obvious reasons.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
When you throw an exception, where do you catch it and what do you do with it?

Surely there must be some way to close the input and output streams, forcing the socket to close which the client should see immediately.

Bill
 
Consider Paul's rocket mass heater.
 
subject: Apache Fileupload via Stream. Possible to cancel the upload?