0
嗨我试图上传一个图像与reactjs,当我从nodejs上载console.log中的图像。我得到一个空数组 任何建议上传图片reactjs/nodejs错误
组件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)
}
你在axios中得到什么回应? –
我收到了一条好消息,问题是reactjs。为什么用html中的表单测试并且工作 –