Когда я интегрирую, реагирую на загрузку изображения flask (python). в прошлый раз также столкнулся с этой проблемой. Доступ к выборке в http://ip/abc/qwerty.jpg из источника http://локальный: 3000 заблокирован политикой CORS: ответ на предварительный запрос не проходит проверку управления доступом: он не имеет статуса HTTP ok.
class VApiPage extends React.Component {
constructor(props) {
super(props);
this._path= this._path.bind(this);
this.state = {
flag:1,
path: "",
res:"",
img:""
}
}
_path(e){
this.setState({
path:e.target.value
});
}
_results(){
let img1= this.state.path;
let str1;
let str;
this.setState({img:img1});
str = "http://0.0.0.0:4000/"+ str1 +"/"+this.state.path;
fetch(str, {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*"
},
})
.then(res => res.json())
.then(res => {
if (window.location.pathname.split("/")[4]== = "gender"){
this.setState({
res: res.Gender
});
}
else if (window.location.pathname.split("/")[4]== = "emotion"){
this.setState({
res: res.Emotion
});
}
});
}
render() {
return (
<div className = "analysis">
<div className = "col-md-3" />
<div className = "col-md-6 visionresult">
</div>
<div className= "col-md-12 test">
<div className = "col-md-1 url">
<form>
<input type = "file" name = "image" onChange = {(e)=>{console.info(e.target.files[0].name);
this.setState({path:e.target.files[0].name,
img:e.target.files[0].name});}}/>
</form>
</div>
<div className = "col-md-8 " >
<textarea className = "links" onChange = {(e)=>this._path(e)} placeholder = "" cols = "100" rows = "1"></textarea>
</div>
</div>
<div className = {this.state.flag===1?"col-md-1 results":""} onClick = {()=>this._results()}>
<button type = "button" className = "btn btn-outline-secondary">Analysis</button>
</div>
<div className = "col-md-12">
<div className = "col-md-2 imgdisplay">
<img src = {this.state.img} width = "100px" height = "100px" alt = "invalid image"/>
</div>
<div className = "col-md-2 displayresult">
<div>{this.state.res}</div>
</div>
</div>
</div>
);
}
}
export default VApiPage;
Вы получаете довольно четкое сообщение об ошибке. Ваши настройки CORS неверны. На этот вопрос отвечали много раз, и простой поиск вашей ошибки в переполнении google/stack дает много результатов как этот, которые уже были решены.
Я не согласен, это вопрос о python-flask, и на него должен быть отдельный ответ. Я лично ищу решение о том, как передать правильные параметры в flask-cors, чтобы избежать этой ошибки.





Возможный дубликат Ответ на предварительный запрос не проходит проверку контроля доступа