Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'file' to callbacks #30

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ReactS3Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var ReactS3Uploader = React.createClass({

getDefaultProps: function() {
return {
onProgress: function(percent, message) {
console.log('Upload progress: ' + percent + '% ' + message);
onProgress: function(percent, message, file) {
console.log('Upload progress: ' + file.name + ' ' + percent + '% ' + message);
},
onFinish: function(signResult) {
console.log("Upload finished: " + signResult.publicUrl)
Expand Down
28 changes: 14 additions & 14 deletions s3upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ S3Upload.prototype.signingUrl = '/sign-s3';
S3Upload.prototype.fileElement = null;
S3Upload.prototype.files = null;

S3Upload.prototype.onFinishS3Put = function(signResult) {
S3Upload.prototype.onFinishS3Put = function(signResult, file) {
return console.log('base.onFinishS3Put()', signResult.publicUrl);
};

S3Upload.prototype.onProgress = function(percent, status) {
return console.log('base.onProgress()', percent, status);
S3Upload.prototype.onProgress = function(percent, status, file) {
return console.log('base.onProgress()', percent, status, file);
};

S3Upload.prototype.onError = function(status) {
S3Upload.prototype.onError = function(status, file) {
return console.log('base.onError()', status);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these methods have been updated, but the actually calling of them hasn't been. Line 40, 87, etc., need to pass file as the third arg it looks like, no?


Expand All @@ -33,11 +33,11 @@ function S3Upload(options) {
}

S3Upload.prototype.handleFileSelect = function(files) {
this.onProgress(0, 'Waiting');
var result = [];
for (var i=0; i < files.length; i++) {
var f = files[i];
result.push(this.uploadFile(f));
this.onProgress(f, 0, 'Waiting');
}
return result;
};
Expand Down Expand Up @@ -84,38 +84,38 @@ S3Upload.prototype.executeOnSignedUrl = function(file, callback) {
try {
result = JSON.parse(xhr.responseText);
} catch (error) {
this.onError('Invalid signing server response JSON: ' + xhr.responseText);
this.onError(file, 'Invalid signing server response JSON: ' + xhr.responseText);
return false;
}
return callback(result);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
return this.onError('Could not contact request signing server. Status = ' + xhr.status);
return this.onError(file, 'Could not contact request signing server. Status = ' + xhr.status);
}
}.bind(this);
return xhr.send();
};

S3Upload.prototype.uploadToS3 = function(file, signResult) {
S3Upload.prototype.uploadToS3 = function(signResult, file) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be (file, signResult) unless line 150 changes.

var xhr = this.createCORSRequest('PUT', signResult.signedUrl);
if (!xhr) {
this.onError('CORS not supported');
this.onError(file, 'CORS not supported');
} else {
xhr.onload = function() {
if (xhr.status === 200) {
this.onProgress(100, 'Upload completed.');
return this.onFinishS3Put(signResult);
this.onProgress(file, 100, 'Upload completed.');
return this.onFinishS3Put(file, signResult);
} else {
return this.onError('Upload error: ' + xhr.status);
return this.onError(file, 'Upload error: ' + xhr.status);
}
}.bind(this);
xhr.onerror = function() {
return this.onError('XHR error.');
return this.onError(file, 'XHR error.');
}.bind(this);
xhr.upload.onprogress = function(e) {
var percentLoaded;
if (e.lengthComputable) {
percentLoaded = Math.round((e.loaded / e.total) * 100);
return this.onProgress(percentLoaded, percentLoaded === 100 ? 'Finalizing' : 'Uploading');
return this.onProgress(file, percentLoaded, percentLoaded === 100 ? 'Finalizing' : 'Uploading');
}
}.bind(this);
}
Expand Down