7.1.x Upload Component: Calling sequence after Upload-Button click

Hi all,

I’ve searched the forum to see if my question has been answered already, but no avail. Please point it out if it has been answered already.

(Vaadin Version 7.1.5.)


What I want to do

After a user clicks on the Upload-Button I’d like to do some checks before the actual upload starts. If these checks fail, I want to cancel the upload prior to creating any actual file on disk (if possible).


Where is the best place to put prior upload checks?

From the documentation
https://vaadin.com/book/vaadin7/-/page/components.upload.html
I understand, that the Upload.Receiver#receiveUpload method is called when I user starts the upload. This method must return an java.io.OutputStream. Also you may register StartedListener listening for the StartedEvent (in the method uploadStarted).


Question

Now from my experience and looking at the source code it seems that the StartedListener gets always called before the receiveUpload method. Is this calling sequence somehow guaranteed? Is the uploadStarted method always called first or may the Upload.Receiver#receiveUpload method get called first?

Which method is the best place to determine whether or not to cancel a started upload immediately (by calling interruptUpload() on Upload component), even before starting to write to the OutputStream?

Best,
YG