I have an image uploader that after the image is uploaded it is processed. The uploading and processing can take more than 5 seconds on a slow connection. I added a way for the user to abort the upload using xhr.abort()
.
The problem I have is once the upload is aborted my pyramid application will continue to process the image, save it to disk, and add the record to the database.
Is there a way for my view to know that the user called xhr.abort()
so I can clean up.
You should receive an event called 'abort' on the xhr-object. If this doesn't work, readystatechange should be fired in every situation.
Source: http://www.w3.org/TR/XMLHttpRequest/#the-abort-method
Edit: How about sending an AJAX-request when the "onabort"-event fires? Then you could undo your changes serverside. To check whether the file arrived complete at the server, you could get the filesize on client-side and send it to the server (http://stackoverflow.com/a/5444716/725629).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With