【发布时间】:2017-06-10 02:37:12
【问题描述】:
您好,当我从 nodejs 上传 console.log 中的图像时,我正在尝试使用 reactjs 上传图像。我得到一个空数组 任何建议
组件 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 中的表单进行测试并工作
标签: node.js forms reactjs express axios