ReactJS中的图像上传表单

时间:2015-12-11 04:22:33

标签: html reactjs

当我点击<button>但点击<input>标记时,我知道为什么这不起作用?使用ReactJS。

此外,如果我按下按钮this.uploadFile无法访问<input>标记中的文件。

<form className="" onSubmit={this.uploadFile}>
  <div className="img-wrapper">
    <UserAvatar userId={ currentUser._id } imageId={ currentUser.profile.picture } size="small" fSize="small" shape="circle" />
    <input type="file" name="avatar" ref="imageInput" accept="image/png, image/jpeg"  multiple="false" />
    <button type="submit" className="">Edit pic</button>
  </div>
</form>

1 个答案:

答案 0 :(得分:0)

请改为尝试:

<div className="img-wrapper">
  <UserAvatar userId={ currentUser._id } imageId={ currentUser.profile.picture } size="small" fSize="small" shape="circle" />
  <input type="file" name="avatar" onChange={ this.uploadFile } ref="imageInput" accept="image/png, image/jpeg"  multiple="false" />
</div>
相关问题