4
I have a <input type="file />
in Vuejs and when I select an image I want it to be converted into base64
, because I will save the images in the database only in base64
. What would be the method to catch only the String
base64
which 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
}
})
}