Reputation: 3068
I am using Javascript API to upload documents to Amazon S3, and I want to handle cases where the upload to s3 is aborted. May be user closes the browser tab or refresh the page (mainly closing of the browser tab)
Is there a way i can handle the case where i can send a request to my server side code when user aborts s3.upload.
I have the below code
let s3Upload = s3.upload(params).on('httpUploadProgress', function(evt) {
jQuery('.export-progress').html("Progress: "+ evt.loaded + "/" + evt.total);
}).promise();
s3Upload.then(function(s3data){
//success processing
}, function(err){
// any error
});
Any help in this would be really great. Many thanks.
Upvotes: 1
Views: 460
Reputation: 163593
Is there a way i can handle the case where i can send a request to my server side code when user aborts s3.upload.
Not really. The Beacon API can be used to fire off a request if the user closes a tab, but what about cases where their battery dies, browser crashes, computer gets rebooted, etc.?
I usually handle this in one of two ways:
Note that both methods are subject to failure, so you should have a cron job or something that regularly sweeps up unexpected items in your bucket, if appropriate for your use case.
Upvotes: 1