I want to upload images in reactjs I am using Formik following https://codesandbox.io/s/lkkjpr5r7?file=/index.js:1808-1812
my code is:
<Field
className="attribute_input"
name={this.props.fieldname}
type="file"
placeholder={
this.props.title
}
onChange={this.handleChange}
/>
and handlechange has the folloing implementations:
handleChange(event) {
const reader = new FileReader();
reader.onload = () => {
if (reader.readyState === 2) {
this.setState({file: reader.result})
}
}
reader.readAsDataURL(event.target.files[0]);
console.log(this.props.fieldname);
this.props.sfv("image1", event.currentTarget.files[0]);
}
Facing error:
Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.