0

This is my code:

var formData = new FormData();
var f = $("#myFile")[0].files[0];

var form = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', form).val();

formData.append('__RequestVerificationToken', token);
formData.append("fileUpload", $("#myFile")[0].files[0]);
$.ajax({
    url: '/GenAI/GetDataFromFile',
    crossDomain: true,
    type: 'POST',
    contentType: false,
    processData: false,
    cache: false,
    data: formData,
    beforeSend: function (xhr) {
        xhr.setRequestHeader('Access-Control-Allow-Origin','*')
        xhr.setRequestHeader("XSRF-TOKEN",$('input:hidden[name="__RequestVerificationToken"]').val());
    },
    success: function (response) {
        alert(response);
    },
    error: function (err) {
        alert(err.statusText);
    }
});
3
  • Your codes for file uploading looks good, could you please share more about the error you are facing? You just mentioned "net::ERR_FAILED while uploading word file", do you mean everything worked well when uploading some other file types?
    – Tiny Wang
    Commented Jun 27 at 2:59
  • Hi Tiny Thanks!!! My code is working for some PDF and for docx files. (but give error on particular docx or pdf files which is just in range of 45-50 kb in size) Commented Jun 27 at 4:18
  • Thanks for your confirmation, but this is not enough for narrow down the issue, do you have any other information which might contain more detailed exception?
    – Tiny Wang
    Commented Jun 27 at 5:01

0

Browse other questions tagged or ask your own question.