• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Apache Fileupload via Stream. Possible to cancel the upload?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic