Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid how to handle an xhr.abort()

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.

like image 216
skrjon Avatar asked Mar 21 '12 03:03

skrjon


1 Answers

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).

like image 140
saegi Avatar answered Sep 23 '22 13:09

saegi