I have <input type="file />
in VueJS and when I select an image I want it to be converted to base64
, because I will save the images in the database only in base64
. What would be the method to get only the String
base64
that gives rise to the image?
<input @change="uploadImage" type="file" name="photo" accept="image/*">
<img :src="imageSrc" class="image">
uploadImage: function (e) {
var files = e.target.files
if (!files[0]) {
return
}
var data = new FormData()
data.append('media', files[0])
var reader = new FileReader()
reader.onload = (e) => {
this.imageSrc = e.target.result
}
})
}