【问题标题】:How to upload file in react?如何在反应中上传文件?
【发布时间】:2018-02-23 02:03:48
【问题描述】:

我试图在 react 中上传文件,但由于请求错误而失败。

这里有一些代码。

uploadDoc = (e) => {
e.preventDefault();
let file = e.target.files[0];
const url = 'https://api.agentcloud.com/api/leadfile/';
const formData = new FormData();
formData.append('lead', this.props.match.params.id);
formData.append('file',file);
const config = {
    headers: {
        'content-type': 'multipart/form-data',
        'Authorization': 'Token 90406829e9d311b117bb7e1484a81e7b7f9f4551'
    }
}
return  post(url, formData, config);

}

【问题讨论】:

标签: javascript python ajax reactjs


【解决方案1】:

删除不完整的内容类型标头。
当您将表单数据对象用于 ajax 时,会为您生成适当的内容类型标头。¹

¹。我不知道反应,所以这可能只是问题的一部分。

【讨论】:

    猜你喜欢
    • 2021-09-13
    • 1970-01-01
    • 2021-02-25
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 2022-12-02
    • 2019-09-03
    相关资源
    最近更新 更多