javascript - 带有 Django/React 的 Axios 补丁:带有非表单的表单数据,不会更新数据库,邮递员工作正常
问题描述
我正在使用 Django 作为后端(REST API)和 React JS 作为前端的项目,使用 Axios 从我的 API 获取。
我尝试使用 imgs 和 JSON(表单数据以及非表单数据)修补数据。 通过选择 img 文件,它在 POSTMAN 中运行良好。但是在我的React 代码中,它不能更新 DB。会有什么问题?
非常感谢!
这是我的反应代码:
//init state
const initialState = {
location: "",
avatar: null,
};
const [dbData, setDbdata] = useState(initialState);
--------
//upload img and setState
let file = event.target.files[0];
setDbdata({
...dbData,
avatar: file,
});
//Axios call
axios.patch(
`api/user/update/username=${state.username}`, dbData, {
headers: {
"content-type": "multipart/form-data;"
},
})
.then((res) => {
console.log(dbData.avatar)
})
.catch((err) => console.log(err.response));
解决方案
推荐阅读
- java - SQL 索引使一些查询花费更长的时间。为什么?
- javascript - 区间范围插入区间而不合并现有区间
- altbeacon - 最新版本 ( 2.15.4 ) 的 Altbeacon 扫描周期要求
- c++ - 为什么我的变量即使不应该被强制初始化为 0?
- javascript - Firestore 功能触发器不会触发
- r - 将行与 R 中的两个匹配列合并
- java - Jersey Spring Boot 添加自定义响应头
- javascript - str.link() ,无法读取未定义错误的属性“链接”
- powerbi - PowerBI 计算组中具有值的所有行
- marklogic - MarkLogic - XQuery 语句的顺序处理