我想使用reactjs上传doc或pdf文件。
我有以下代码:
<div className="progress-value">
<input type="file" onChange={(e) => this.lofuploadChange(e)} />
<div style={{ paddingTop: "8px" }}>
<span className="orangeText">browse</span>
</div>
</div>
<div className="btn btn-upload" type="button" onClick={(e) => this.lofupload(e)}>Upload</div>
功能
lofuploadChange = (e) => {
this.setState({
file:e.target.files[0]
});
}
lofupload = (e) => {
const formData = new FormData();
formData.append('docFile', this.state.file);
//In console I am getting prorer file object, while I send it through Request its sends like {} in payload of request. Why its happening ?
}
如果我出错了,请指导我。我也在请求标头中发送multipart/form-data