7

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.

Marty
  • 39,033
  • 19
  • 93
  • 162
skrjon
  • 71
  • 1

1 Answers1

1

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

saegi
  • 36
  • 3
  • This explains how it is supposed to work client side. I am not sure how that message comes across server side. – skrjon Mar 26 '12 at 16:58
  • oh sorry i hadn't read your question exactly.. so you want to know how you can "capture" an abort serverside? – saegi Apr 04 '12 at 07:31