Reputation: 108
I'm trying to send a base64 encoded string to my server but the data binding I use is "" in the function to send it.
This is the code:
processFile: function(event) {
var rawFile = event.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(rawFile);
reader.onload = function() {
this.file = reader.result.split(',')[1];
};
},
So this.file contains the base64 string but when I access it in another function it's returning ""
What am I doing wrong here?
Upvotes: 0
Views: 48
Reputation: 1660
Try
processFile: function(event) {
var rawFile = event.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(rawFile);
reader.onload = function() {
this.file = reader.result.split(',')[1];
}.bind(this);
},
or
processFile: function(event) {
var rawFile = event.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(rawFile);
var vm = this;
reader.onload = function() {
vm.file = reader.result.split(',')[1];
};
},
Upvotes: 1