I have a input field "type=file" that allows user to upload video file.
<input type="file" class="form-control" id="file1" />
I want to retrieve file content (Video) from the input field and send it with XMLHttpRequest(). How can i achieve it ? This is my code but, it is not working.
I want to save video file to SharePoint online with XMLHttpRequest().
var studentName = "Test";
var extension = ".mp4";
var VideoFile = "";
const fileInput = document.querySelector('input');
//Updated code
let file = document.getElementById('file1')[0];
let formData = new FormData();
formData.append("video", file);
var fullPath = document.getElementById('file1').value;
extension = fullPath.split('.').pop();
//build http request string using URL from Power Automate flow
var StudentVideo = '{ "StudentVideo" : [' +
'{ "studentName": "' + studentName +'","VideoFile":"' + formData +'",
"extension":"' + extension +'"} ]}';
var req = new XMLHttpRequest();
var url = "......./triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=............";
//send https request to Power Automate
req.open("POST", url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.send(StudentVideo);