Skip to content

Commit

Permalink
Merge pull request lenage#2 from AndreLion/upload-progress-callback
Browse files Browse the repository at this point in the history
Add progress callback
  • Loading branch information
lenage committed Sep 12, 2015
2 parents d5b6c23 + 1f5f34a commit f817a60
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var ReactQiniu = React.createClass({
if (!file || file.size === 0) return null;
var url;
var key = file.preview.split('/').pop() + '.' + file.name.split('.').pop();
var _this = this;
if (this.props.prefix) {
key = this.props.prefix + key;
}
Expand All @@ -102,11 +103,20 @@ var ReactQiniu = React.createClass({
.field('x:size', file.size)
.attach('file', file, file.name)
.set('Accept', 'application/json')
.on('progress', function (e) { file.progress = e.percent;})
.on('progress', function (e) {
if(_this.isFunction(file.onprogress)){
file.onprogress(e.percent);
}
})
.promise()
return promise;
},

isFunction: function(fn) {
var getType = {};
return fn && getType.toString.call(fn) === '[object Function]';
},

render: function() {
var className = this.props.className || 'dropzone';
if (this.state.isDragActive) {
Expand Down

0 comments on commit f817a60

Please sign in to comment.