我决定在本地项目中存储文件。我希望当用户点击提交时,文件将被保存到一个路径,我将对文件名发送一个Post请求到一个目录。如何将文件对象保存到本地目录?
export default class Example extends React.Component {
constructor (props) {
super(props);
this.fileInput;
this.handleFormSubmit = this.handleFormSubmit.bind(this);
}
handleFormSubmit(e) {
e.preventDefault()
path = "../../images"
// Save this.fileInput to path directory
}
render() {
function FieldGroup({ id, label, help, ...props }) {
return (
<FormGroup controlId={id}>
<ControlLabel>{label}</ControlLabel>
<FormControl {...props} />
</FormGroup>
);
}
return (
<Form>
<FieldGroup
id="formControlsText"
type="text"
label="title"
placeholder="Enter text"
/>
<FieldGroup
id="formControlsFile"
type="file"
label="Image"
help="Example block-level help text here."
inputRef={ref => {this.fileInput = ref}}
/>
<Button> Submit </Button>
</Form>
);
}
}
答案 0 :(得分:-1)
你必须在你的后端使用强大或闷闷不乐。或者,您可以在线创建存储桶,并创建一个发布请求以将图像存储在存储桶中。