I am developing a file picker with Vue.js. I want to show selected file previews.
I use FileReader API to achieve this. I read the user selected files as data urls with readAsDataURL method of the FileReader object.
However I get an error message saying reader.onload is not a function like:
Uncaught TypeError: reader.onload is not a function
at VueComponent.handleFileChanges
It may be the reader is not defined, following the FileReader undefined error I have mentioned above.
How I try to do do this is as follows:
handleFileChanges (e) {
var reader = new window.FileReader() // if window is not used it says File READER is not defined
reader.onload(function (event) {
// dispatch fileAttached to state UI postEditor with event.target.result as read dataURL
let imageDataURL = event.target.result
this.$store.dispatch('attachedFile', imageDataURL) // or previewFile
})
reader.readAsDataURL(e.target.files[i])
}
What is the point I am missing?