Hi I'm trying to upload an image with reactjs, when I upload the image in console.log from nodejs. I get an empty array Any suggestions
component reactjs
export default class Categoria extends Component {
constructor(props) {
super(props);
this.state= {}
this.handleSubmit=this.handleSubmit.bind(this)
}
render(){
return (
<form onSubmit={this.handleSubmit.bind(this)} encType="multipart/form-data">
<input type="file" onClick={this.handleImageChange.bind(this)} name="photo" />
<button type="submit">upload picture </button>
</form>
)
}
handleImageChange(e) {
this.setState({photo: e.target.files[0]});
}
handleSubmit(e) {
e.preventDefault()
axios.post("x/photos", this.state.photo)
.then((response) =>{
console.log(response.data)
})
.catch((err)=>{
console.log(err)
})
}
}
// router nodejs
router.post('/x/photos', function(req, res){
console.log(req.body.photo)
}
via FERNANDO ORTIZ
No comments:
Post a Comment