i'm using "react-images-upload" to upload images from react to django api but when i submit the form i does not get posted to the django api knowing that it used to work before adding the image uplopad and it works when post it in the api just not in react
export default class CreatePost extends Component {
constructor(props) {
super(props);
this.state = {
title: this.props.title,
main_post: this.props.main_post,
thumbnail: this.props.thumbnail,
pictures: []
};
this.handlethumbnail = this.handlethumbnail.bind(this);
}
handlethumbnail(picture) {
this.setState({
pictures: this.state.pictures.concat(picture),
});
}
handleSubmitButton() {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title: this.state.title,
main_post: this.state.main_post,
thumbnail: this.state.pictures[0],
}),
};
fetch("/api/Create-Post", requestOptions)
.then((response) => response.json())
.then(this.props.history.push("/"));
}
render() {
return (
<>
<ImageUploader
singleImage={true}
buttonText='Choose images'
onChange={this.handlethumbnail}
imgExtension={['.jpg', '.gif', '.png', '.gif']}
maxFileSize={5242880}
/>
}
</>
i also configured the media folder in setting.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
and in urls.py
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)