I am trying to upload files using kendoFileManager control in the worker thread as I have some pre-upload check on the files which might take time.
I have following code in my worker -
worker.js
onmessage = function(filesArray) {
var fileData = new FormData();
// if there are multiple files , loop through each files
for (var i = 0; i < message.data.length; i++) {
fileData.append(message.data[i].name, message.data[i]);
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "/SelfServiceAI/Upload3/", true);
xhr.setRequestHeader('Accept', 'multipart/form-data');
xhr.withCredentials = true;
xhr.onload = () => { // Call a function when the state changes.
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
//postMessage("File successfully uploaded")
// Request finished. Do processing here.
}
else {
//postMessage("File upload failed!");
}
}
xhr.send(fileData);
}
This worker is created and invoked on the upload event of the kendo FileManagerControl.
$("#filemanager").kendoFileManager({
....
upload : {
upload : function (e) {
const worker = new Worker(worker.js);
worker.postMessage(e.sender.getFiles());
}
},
....
});
controller action method -
public JsonResult Upload ()
{
HttpFileCollectionBase files = Request.Files;
// Other processing logic
}
For me, the Request.Files is coming up as empty and there is no other property in Request that can be used to get the Files data for upload. I am expecting a way to get the files passed from the UI in the controller action method.