Skip to content

Instantly share code, notes, and snippets.

@kizdolf
Created March 3, 2016 19:12
Show Gist options
  • Save kizdolf/426614edd3a71f254f4d to your computer and use it in GitHub Desktop.
Save kizdolf/426614edd3a71f254f4d to your computer and use it in GitHub Desktop.
request.post(this.props.url)
.attach('file', file, file.name)
.on('progress', function(e){
var elem = {name: file.name, pct: parseInt(e.percent).toString() + '%'};
var current = this.state.uploading;
current[file.name] = elem;
this.setState({ uploading: current });
}.bind(this))
.on('error', function(err){
var current = this.state.uploading;
current[file.name].pct = 'error uploading :/';
this.setState({ uploading: current });
})
.end(function(res){
var current = this.state.uploading;
current[file.name].pct = 'Finished.';
this.setState({ uploading: current });
setTimeout(function(){
delete current[file.name];
this.setState({ uploading: current });
}.bind(this), 3500);
}.bind(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment