diff --git a/index.js b/index.js index 8589744..217388f 100644 --- a/index.js +++ b/index.js @@ -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; } @@ -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) {