Currently, I am utilizing FileReader() in order to access file values. Is there a method to initiate an Http post request for posting multiple file values as input?
var fi = document.getElementById('myFile');
if (fi.files.length > 0) {
for (var i = 0; i < fi.files.length; i++) {
var reader = new FileReader();
reader.readAsDataURL(fi.files[i]);
var f = fi.files[i];
file_input = reader.result.split("base64,").pop();
var attachment_type = fi.files[i].type;
var filename = fi.files[i].name;
}
}
Performing the HTTP request
var data = JSON.stringify(
{
"firstname": First,
"lastname": Last,
"file": [
{
"input_file": file_input,
"attachment_type": attachment_type,
"file_name": filename
} ] } );
var url = "";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true)
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send(data);