I am doing pdf upload in react js. I want to upload pdf file and just wants to show on the top of the upload button with small div along with remove button, if I click on the remove then it should be removed.
The same I have done it for image successfully. I can upload image and also can preview. But I need some help in doing pdf upload
here is my code,
this.state = {
file: '',
imagePreviewUrl: ''
}
getPhoto (e) { e.preventDefault();
let reader = new FileReader();
let file = e.target.files[0];
reader.onloadend = () => {
this.setState({
file: file,
imagePreviewUrl: reader.result
});
}
reader.readAsDataURL(file);
}
render() {
const { imagePreviewUrl, file } = this.state;
let imagePreview = null;
if (imagePreviewUrl) {
imagePreview = (<img src={imagePreviewUrl} />);
} else {
imagePreview = (<div className="previewText">Please select an Image for Preview</div>);
}
return (
<React.Fragment>
<div className={styles.previewBlock}>
{imagePreview}
<div className={styles.fileName}>{file.name}<span>
<i className="fa fa-times" /></span></div>
</div>
)
}