Subject.js
2.97 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import Widget from '../../components/Widget/Widget';
import {
Row,
Col,
Button,
Form,
FormGroup,
Label,
} from 'reactstrap';
class Subject extends PureComponent {
constructor(props) {
super(props);
this.onChangeInputImage = this.onChangeInputImage.bind(this);
this.onClickSaveImage = this.onClickSaveImage.bind(this);
this.state = {
imageFiles: [],
};
}
onChangeInputImage(e) {
const files = [];
const reader = new FileReader();
files.push(e.target.files[0]);
reader.onloadend = () => {
files[0].preview = reader.result;
files[0].toUpload = true;
this.setState({
imageFiles: files,
});
};
reader.readAsDataURL(e.target.files[0]);
}
onClickSaveImage(e) {
e.preventDefault();
console.log(this.state.imageFiles);
console.log("save image");
this.setState({
imageFiles:[],
});
// post request
}
render() {
return (
<div>
<h1 className="page-title mb-xlg mt-lg">Photo <small>Upload</small></h1>
<Row>
<Col lg="6" md={12}>
<Widget
>
<Form>
<blockquote className="blockquote blockquote">
<p>침입자로 분류하지 않을 방문자의 사진을 업로드 하세요.</p>
</blockquote>
<FormGroup style={{margin:'10px 0px 0px 0px'}}>
<Col md="8">
<input
accept="image/*" onChange={this.onChangeInputImage}
id="fileupload"
type="file" name="file" className="display-none"
/>
{this.state.imageFiles.length > 0 ? <div>
{this.state.imageFiles.map((file, idx) => (
<img alt="..." src={file.preview} key={`img-id-${idx.toString()}`} />))}
</div> : <img
alt="..."
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTEiIGhlaWdodD0iMTQxIj48cmVjdCB3aWR0aD0iMTkxIiBoZWlnaHQ9IjE0MSIgZmlsbD0iI2VlZSIvPjx0ZXh0IHRleHQtYW5jaG9yPSJtaWRkbGUiIHg9Ijk1LjUiIHk9IjcwLjUiIHN0eWxlPSJmaWxsOiNhYWE7Zm9udC13ZWlnaHQ6Ym9sZDtmb250LXNpemU6MTJweDtmb250LWZhbWlseTpBcmlhbCxIZWx2ZXRpY2Esc2Fucy1zZXJpZjtkb21pbmFudC1iYXNlbGluZTpjZW50cmFsIj4xOTF4MTQxPC90ZXh0Pjwvc3ZnPg=="
/>}
<div>
<Button type="button" color="default" onClick={this.onClickSaveImage} style={{margin:'10px 0px 0px 0px'}}>Upload Image</Button>
</div>
</Col>
</FormGroup>
</Form>
</Widget>
</Col>
</Row>
</div>
);
}
}
function mapStateToProps(state) {
return {
labelData: state.labelData,
}
}
export default connect(mapStateToProps)(Subject);