2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-07-15 23:05:18 +00:00
|
|
|
import Dropzone from 'dropzone';
|
2016-07-19 20:49:46 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2017-02-22 19:29:35 +00:00
|
|
|
import * as UploaderActions from '../actions/uploader';
|
2018-02-01 21:45:19 +00:00
|
|
|
import { fileExtensionsAndMimeTypes } from '../../../../server/utils/fileUtils';
|
2017-02-22 19:29:35 +00:00
|
|
|
|
2018-08-24 21:41:23 +00:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const s3Bucket = __process.env.S3_BUCKET_URL_BASE ||
|
|
|
|
`https://s3-${__process.env.AWS_REGION}.amazonaws.com/${__process.env.S3_BUCKET}/`;
|
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() {
|
2017-04-06 20:22:34 +00:00
|
|
|
const userId = this.props.project.owner ? this.props.project.owner.id : this.props.user.id;
|
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,
|
2016-11-30 00:18:11 +00:00
|
|
|
maxFiles: 6,
|
|
|
|
parallelUploads: 2,
|
2016-10-28 20:19:56 +00:00
|
|
|
maxFilesize: 5, // in mb
|
2016-11-30 00:18:11 +00:00
|
|
|
maxThumbnailFilesize: 8, // 8 mb
|
2016-07-20 01:42:33 +00:00
|
|
|
thumbnailWidth: 200,
|
|
|
|
thumbnailHeight: 200,
|
2018-02-01 21:45:19 +00:00
|
|
|
acceptedFiles: fileExtensionsAndMimeTypes,
|
2020-03-03 21:33:52 +00:00
|
|
|
dictDefaultMessage: 'Drop files here or click to use the file browser',
|
2017-04-06 20:22:34 +00:00
|
|
|
accept: this.props.dropzoneAcceptCallback.bind(this, userId),
|
2016-07-19 20:49:46 +00:00
|
|
|
sending: this.props.dropzoneSendingCallback,
|
2017-04-06 18:34:14 +00:00
|
|
|
complete: this.props.dropzoneCompleteCallback
|
2016-10-25 01:15:32 +00:00
|
|
|
// error: (file, errorMessage) => {
|
|
|
|
// console.log(file);
|
|
|
|
// console.log(errorMessage);
|
|
|
|
// }
|
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,
|
2017-04-06 18:34:14 +00:00
|
|
|
dropzoneCompleteCallback: PropTypes.func.isRequired,
|
|
|
|
project: PropTypes.shape({
|
|
|
|
owner: PropTypes.shape({
|
2017-04-06 20:22:34 +00:00
|
|
|
id: PropTypes.string
|
2017-04-06 18:34:14 +00:00
|
|
|
})
|
2017-04-06 20:22:34 +00:00
|
|
|
}),
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string
|
2017-04-06 18:34:14 +00:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
FileUploader.defaultProps = {
|
|
|
|
project: {
|
|
|
|
id: undefined,
|
2017-04-06 20:22:34 +00:00
|
|
|
owner: undefined
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
id: undefined
|
2017-04-06 18:34:14 +00:00
|
|
|
}
|
2016-07-19 20:49:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
files: state.files,
|
2017-04-06 20:22:34 +00:00
|
|
|
project: state.project,
|
|
|
|
user: state.user
|
2016-07-19 20:49:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UploaderActions, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(FileUploader);
|