I am currently trying to upload file with javascript to Google Drive. Everything works fine, but I am not sure what I have to add to give name to my uploaded file.
function uploadFile(){
var form = new FormData();
var xhttp = new XMLHttpRequest();
xhttp.responseType = 'blob';
var fileID = document.getElementById('fileName').value;
var apiKeyId = "{MY_API_KEY}";
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
console.log('Uploaded');
}
};
xhttp.open("POST", "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart", true);
xhttp.setRequestHeader("Authorization", "Bearer "+userToken);
var sendFiles = document.getElementById("sendFile");
if ('files' in sendFiles) {
if (sendFiles.files.length == 0) {
} else {
for (var i = 0; i < sendFiles.files.length; i++) {
var file = sendFiles.files[i];
xhttp.send(file);
}
}
}
}