I'm using Reactjs in frontend.
I've set the profilePicture to state with this code
handleImageChange = (event) => {
event.preventDefault();
var file = event.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = function (e) {
this.setState({
profilePicture: e.target.result //don't know how it is working
});
}.bind(this);
}
and I can preview the image file:
<img src={this.state.profilePicture} alt="img"/>
I want to send these data to server:
data = {
'profilePicture': anImageFile,//this.state.profilePicture
'photos': [anotherImage, anotherImage2, anotherImage3],
'personal_info': {
'name': 'User Name',
'anyList': [1,2,3]
}
}
Can I do it using fetch?
this.state.profilePictureis just a data url (likedata:image/png,...) you can just send that as the profile picture in the request.data:image/png;base64,iVBORw0K...) and the url is too long.