2016-07-19 20:49:46 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-07-15 23:05:18 +00:00
|
|
|
import Dropzone from 'dropzone';
|
2016-07-21 00:30:40 +00:00
|
|
|
const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`;
|
2016-07-19 20:49:46 +00:00
|
|
|
import * as UploaderActions from '../actions/uploader';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2016-07-15 23:05:18 +00:00
|
|
|
|
|
|
|
class FileUploader extends React.Component {
|
|
|
|
componentDidMount() {
|
2016-07-20 22:37:49 +00:00
|
|
|
this.createDropzone();
|
2016-07-16 00:01:21 +00:00
|
|
|
Dropzone.autoDiscover = false;
|
2016-07-20 22:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createDropzone() {
|
2016-07-16 00:01:21 +00:00
|
|
|
this.uploader = new Dropzone('div#uploader', {
|
2016-07-15 23:05:18 +00:00
|
|
|
url: s3Bucket,
|
|
|
|
method: 'post',
|
|
|
|
autoProcessQueue: true,
|
|
|
|
clickable: true,
|
|
|
|
maxFiles: 1,
|
|
|
|
parallelUploads: 1,
|
|
|
|
maxFilesize: 10, // in mb
|
|
|
|
maxThumbnailFilesize: 8, // 3MB
|
2016-07-20 01:42:33 +00:00
|
|
|
thumbnailWidth: 200,
|
|
|
|
thumbnailHeight: 200,
|
2016-07-21 18:18:38 +00:00
|
|
|
acceptedFiles: 'image/bmp,image/gif,image/jpg,image/jpeg,image/png,audio/*',
|
2016-07-20 01:42:33 +00:00
|
|
|
dictDefaultMessage: 'Drop files here to upload or click to use the file browser',
|
2016-07-19 20:49:46 +00:00
|
|
|
accept: this.props.dropzoneAcceptCallback,
|
|
|
|
sending: this.props.dropzoneSendingCallback,
|
|
|
|
complete: this.props.dropzoneCompleteCallback
|
2016-07-16 00:01:21 +00:00
|
|
|
});
|
2016-07-15 23:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div id="uploader" className="uploader dropzone"></div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 20:49:46 +00:00
|
|
|
FileUploader.propTypes = {
|
|
|
|
dropzoneAcceptCallback: PropTypes.func.isRequired,
|
|
|
|
dropzoneSendingCallback: PropTypes.func.isRequired,
|
|
|
|
dropzoneCompleteCallback: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
files: state.files,
|
|
|
|
project: state.project
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UploaderActions, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(FileUploader);
|