Skip to content

Commit

Permalink
Fix broken resume + progress after resume
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-mindrov committed Jan 19, 2014
1 parent 25a64d2 commit ae9f867
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions vendor/assets/javascripts/s3_multipart/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,8 @@ function Upload(file, o, key) {

upload.signPartRequests(id, object_name, upload_id, parts, function(response) {
_.each(parts, function(part, key) {
var xhr = part.xhr;

xhr.open('PUT', 'http://'+upload.bucket+'.s3.amazonaws.com/'+object_name+'?partNumber='+part.num+'&uploadId='+upload_id, true);
xhr.setRequestHeader('x-amz-date', response[key].date);
xhr.setRequestHeader('Authorization', response[key].authorization);

part.date = response[key].date;
part.auth = response[key].authorization;
// Notify handler that an xhr request has been opened
upload.handler.beginUpload(pipes, upload);
});
Expand All @@ -435,6 +431,7 @@ function UploadPart(blob, key, upload) {
this.size = blob.size;
this.blob = blob;
this.num = key;
this.upload = upload;

this.xhr = xhr = upload.createXhrRequest();
xhr.onload = function() {
Expand All @@ -444,14 +441,18 @@ function UploadPart(blob, key, upload) {
upload.handler.onError(upload, part);
};
xhr.upload.onprogress = _.throttle(function(e) {
if (upload.inprogress[key] != 0) {
if (e.lengthComputable) {
upload.inprogress[key] = e.loaded;
}
}, 1000);

};

UploadPart.prototype.activate = function() {
this.xhr.open('PUT', 'http://'+this.upload.bucket+'.s3.amazonaws.com/'+this.upload.object_name+'?partNumber='+this.num+'&uploadId='+this.upload.upload_id, true);
this.xhr.setRequestHeader('x-amz-date', this.date);
this.xhr.setRequestHeader('Authorization', this.auth);

this.xhr.send(this.blob);
this.status = "active";
};
Expand Down

0 comments on commit ae9f867

Please sign in to comment.