forked from odysseyscience/react-s3-uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReactS3Uploader.js
47 lines (38 loc) · 1.23 KB
/
ReactS3Uploader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var React = require('react'),
S3Upload = require('./s3upload.js');
var ReactS3Uploader = React.createClass({
propTypes: {
signingUrl: React.PropTypes.string.isRequired,
onProgress: React.PropTypes.func,
onFinish: React.PropTypes.func,
onError: React.PropTypes.func
},
getDefaultProps: function() {
return {
onProgress: function(percent, message) {
console.log('Upload progress: ' + percent + '% ' + message);
},
onFinish: function(signResult) {
console.log("Upload finished: " + signResult.publicUrl)
},
onError: function(message) {
console.log("Upload error: " + message);
}
};
},
uploadFile: function() {
new S3Upload({
fileElement: this.getDOMNode(),
signingUrl: this.props.signingUrl,
onProgress: this.props.onProgress,
onFinishS3Put: this.props.onFinish,
onError: this.props.onError
});
},
render: function() {
return this.transferPropsTo(
React.DOM.input({type: 'file', onChange: this.uploadFile})
);
}
});
module.exports = ReactS3Uploader;