How to check server session before upload?

I am working on integrating avatar upload into my webapp using Uppy Dashboard, Image Editor and XHR Upload. The server side is Apache Tomcat. I need help on how to implement a solution to the problem, how to avoid failing upload due to expired server session. If for example image editing phase takes long time, it may happen that server session expires meantime. I think that a good solution could be to check if session is alive BEFORE starting upload. I think “onBeforeUpload” might be a good place to run this check. I tried to call an Ajax check from there and not to allow to start upload based on the result, but no success: I was not able to abort the upload process.

Is onBeforeUpload the right way to do that? Many thanks in advance for any comment. A working example would be highly appreciated.