I am using URL.createObjectURL() to convert image to blob URL and saving it to database. Now i want to call that URL and convert it back to Image and display it
Converting to URL
onImageChange = event => {
if (event.target.files && event.target.files[0]) {
let img = event.target.files[0];
this.setState({
image: URL.createObjectURL(img)
});
console.log(this.state.image);
}
};
calling the file
<td className="text-left">{offers.offertitle}</td>
<td className="text-left">{offers.offerdescription}</td>
<td className="text-left"><img src={offers.offerimg} /></td>
saving the URL to DB
onSubmit = e => {
e.preventDefault()
addItem({offertitle: this.state.offertitle, offerdescription: this.state.offerdescription,offerimg: this.state.image ,vid: this.state.vid}).then(() => {
this.getAll()
toastr.success('Offer Added Succesfully', 'Uni Perks', { timeOut: 800 })
setTimeout(() => {
window.location.reload();
}, 1000);
})
this.setState({
offertitle: '',
offerdescription:'',
})
}