
[英]How do I fix React: The string did not match the expected pattern error
[英]Uploading file keeps getting "The string did not match the expected pattern"
当我发布 API 请求时,我不断收到此问题。 我想将文件发布到后端(使用 MERN)。 虽然我的其他 post/put/get 请求运行顺利,但只有这部分响应不佳。 这是我发布照片文件的代码:
<Paper variant="outlined" className={classes.first}>
<form onSubmit = {handleSubmit}>
<input type = "file"
accept="image/*"
onChange = {e => {
setPhoto(e.target.files[0])
}} />
<Button variant="contained" color="primary"
type = "submit"
>Add photo</Button>
</form>
</Paper>
这是我的提交功能:
const handleSubmit = async (e) => {
e.preventDefault();
console.log(photo);
const URL = Config.Local_API_URL.concat("photos/upload");
const formData = new FormData();
formData.append('userID', user.id);
formData.append('photoImage', photo);
console.log(photo);
const config = {
headers: {
'content-type': 'multipart/form-data'
}
}
await axios.post(URL, formData, config).then(res => console.log("success"))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.