단일 이미지 파일을 업로드하고 해당 경로를 데이터베이스에 저장하려고합니다. 그러나 업로드 된 이미지 (앱의 상태에 저장되는 세부 정보)를 보내려고하면 전송 된 이미지와 관련하여 요청의 페이로드가 비어 있습니다.React JS 파일 업로드
onDrop(picture) {
this.setState({
images: this.state.images.concat(picture)
});
}
그리고 handleSubmit :이 t는
handleSubmit(event) {
event.preventDefault();
console.log(this.state.images) // at this point, the list of files is populated, as present in the image below.
axios.post('http://127.0.0.1/scoala-de-iarna/api/web/api/create-sponsor', {
name: this.state.name,
images: this.state.images
});
}
입니다
renderForm() {
return (
<div>
<form onSubmit={ this.handleSubmit }>
<div className="uniform">
<div className="12u 12u%(medium)">
<ImageUploader
withIcon={ true }
buttonText='Upload'
onChange={ this.onDrop }
imgExtension={ ['.jpg', '.png'] }
maxFileSize={ 6291456 }
/>
</div>
</div>
</form>
<input /*onClick={ this.handleSubmit }*/ type="submit" value="Submit" />
</div>
);
}
가 여기 내 onDrop 핸들러입니다 : 여기
내 구성 요소의 그는 파일 - 업로드 될 목록입니다.이
요청의 데이터입니다.업데이트 - 행동 폴더에 createSponsor 기능 :
export function createSponsor(values) {
return async (dispatch, getState) => {
await axios({
url: `${ROOT_URL}api/create-sponsor`,
method: 'post',
data: {
name: values.name,
images: values.images
}
})//.then((response) => dispatch(dispatchCreateSponsor(response)));
.then(response => console.log(response))
}
}
나는 액시스와 함께 비동기 대기를 사용하여 조치를 작성했습니다. 이전에 언급 한 작업으로 질문을 업데이트했습니다. 그러나 비동기식 대기 상태 일지라도 요청 페이로드에 여전히 파일 목록이 비어 있습니다. –