나는 해결책을 찾았지만 여전히 그것을 구현하는 더 좋은 방법이 필요하다.
import React, { Component } from 'react';
import Button from 'material-ui/Button';
import FormControl from '../formcontrol';
class FileUpload extends Component {
constructor(props) {
super(props);
this.state = {
file: []
};
this.onClick = this.onClick.bind(this);
this.onChange = this.onChange.bind(this);
}
onClick = (inputValue) => {
document.getElementById("fileInput").click()
}
onChange = (file, onChange) => {
console.log(this.state.file);
}
render() {
const { classes, onChange } = this.props;
const { file } = this.state;
return (
<FormControl>
<div>
<input type="file" style={{ display: 'none' }} id="fileInput" onChange={e => {
this.onChange(e.currentTarget.files[0], onChange);
}} />
<Button className={classes.button}
raised
containerElement='label'
color="default"
label='My Label'
onClick={(event) => this.onClick(event)} }>
Upload
< Icon className={this.props.classes.rightIcon}>file_upload</Icon>
</Button>
</div>
</FormControl >
);
}
}
export default FileUpload;
왜 작동하지 않는지에 대한 설명을 더 줄 수 있습니까? 그것은 오류를 던지고 있습니까? 업로드 시간이 초과 되었습니까? 양식 게시 이후입니까? 어떤 브라우저를 사용하고 있습니까? – Jack