如何在reactjs中的请求中发送formData /如何在没有formData的情况下上传文件?

时间:2018-07-23 12:41:13

标签: reactjs file-upload multipartform-data form-data

我想使用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

0 个答案:

没有答案