title: file upload in javascript and send file through api
body: <p>I'm trying to upload a file and send that via api as a file.But not getting working. Here is my used for upload and send my file to api.
  But it most probably terns to the error message.</p>
  
  <pre><code>$(document).on('change', '#txtUploadFile', function(e){
  
      var files = e.target.files;
      if (files.length &gt; 0) {
         if (this.value.lastIndexOf('.xlsx') === -1){
            alert('Only ods files are allowed!');
            this.value = '';
            return;
         }
         if (window.FormData !== undefined) {
             var data = new FormData();
             for (var x = 0; x &lt; files.length; x++){
                 data.append("file" + x, files[x]);
             }
  
             $.ajax({
                 type: "POST",
                 contentType: "multipart/form-data",
                 url: 'http://localhost/clicportaltest/rest/clicadmin/uploadExcel',
  
                 data:{file:file},
                 success: function(result) {
                     console.log(result);
                 },
                 error: function (xhr, status, p3, p4){
                     var err = "Error " + " " + status + " " + p3 + " " + p4;
                     if (xhr.responseText &amp;&amp; xhr.responseText[0] == "{")
                         err = JSON.parse(xhr.responseText).Message;
                         console.log(err);
                      }
                  });
          } else {
              alert("This browser doesn't support HTML5 file uploads!");
            }
       }
  });
  </code></pre>