Wherever I have the UI for uploading the document, I am easily able to use FormData api for uploading asynchronously to web api. Now I have a scenario where I need to upload a document based on file path without using UI or User Input so how can I do that?
Below is the code that I use when user uploads the file in form.
var formData = new FormData();
var myFile = $('#myFile')[0];
formData.append("myFile", myFile.files[0]);
$.ajax({
url: url,
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, ajaxOptions, rtnError) {
alert(xhr.responseText + rtnError);
}
});