recently I did that and I pass my portion of code, hopefully it will help:
$('#myFile').on('change', function (e) {
readFile(this.files[0], function (e) {
bytes = (e.target.result);
console.log(bytes);
});
});
This will print something like this:
data: application / pdf; base64, JVBERi0xLjUKJYCAgIAKMTEgMC ...
However, if you are going to occupy it in ajax, the data: application / pdf; base64 part will not be very useful, you can remove it with a:
bytes.replace("data:" + formato + ";base64,", "")
the format you take with a:
formato = this.files[0].type;
It is worth mentioning that this occupies it to attach a file and be able to send it through an email which was a WS in JAVA