How to send a file to base 64 using FormData?

Hello! How to convert image to base64 using formData? The code represents the standard version, and I need the base64

var request = new XMLHttpRequest();
 request.open('POST', 'identity/', true);
 var data = new FormData(document.forms.profileForm);

 var file = document.getElementById('addFile');

console.log(file.files);

 if (file.files.length) {
 data.append('foto', file.files[0]);
}
console.log(data.get('foto'));

 request.onreadystatechange = function() {
 console.log("request.status>" + request.status);
 if (request.readyState === 4 && request.status === 200) {
 console.log("request.responseText>" + request.responseText);
 var arrJson = JSON.parse(request.responseText);
console.log(arrJson);
}
 if (request.status == "400") {
 console.log("400" + request.responseText);
 var json = JSON.parse(request.responseText);
}
}
 request.send(data);
April 19th 20 at 12:02
0 answer

Find more questions by tags jQueryJavaScriptAJAX