Good Day, how can I change my code so that it will accept multiple image upload with preview and user can delete and set a primary image.
My code only allows one image upload by the way.
This is what I've got so far:
_handleImageChange(e) {
e.preventDefault();
let reader = new FileReader();
let file = e.target.files;
console.log('file', file);
console.log('reader', reader);
reader.onloadend = () => {
this.setState({
file: file,
imagePreviewUrl: reader.result
});
this.props.onImageChange(this.state);
}
reader.readAsDataURL(file);
}
render(){
let { imagePreviewUrl } = this.state;
let $imagePreview = null;
let path = Config.PROJECT_PATH + '' + Config.IMAGE.PATH + '' + this.props.imageModule + '/thumb/' + this.props.image;
if (imagePreviewUrl) {
$imagePreview = (<ThumbImage image={imagePreviewUrl} ref='myImage'/>);
}
else{
if (this.props.image) {
$imagePreview = (<ThumbImage image={path} />);
}
else{
$imagePreview = (<ThumbImage image={defaultImage} />);
}
}
return(
<div>
<div className="modal-image-preview">
{ $imagePreview }
</div>
<div className="modal-image-button">
<form onSubmit={(e)=>this._handleSubmit(e)}>
<RaisedButton style= {{ backgroundColor: '#000' }} containerElement='image' label="Choose an Image" labelPosition="before" onChange={(e)=>this._handleImageChange(e)}>
<input type="file" style={styles.imageInput} multiple/>
</RaisedButton>
</form>
</div>
</div>
);
}
Your help is very much appreciated.