I am new to `laravel` and i want to send a file to a controller using javascript. I've seen examples for `FormData` object but i do not want to use that because i want to get file object from Request Object in controller. Instead of `FormData` i am making a request\_data string. i am successfully able to post string variables but when i put file inside that request\_data string i am not unable to get the file inside controller. Below is my code. 

**javascript**

```
var file = form.task_file.files[0];
var http = null;
    var url = "http://".concat(window.location.hostname).concat("/pms/upload_task_file");
    if (window.XMLHttpRequest) {
        http = new XMLHttpRequest();
    }

    http.onreadystatechange = function () {            
        alert(http.response);
    }
    const request_data= `task_file=${file}`;          
    http.open('POST', url, true);
    http.setRequestHeader('Content-type', 'multipart/form-data');
    http.setRequestHeader("X-CSRF-Token", form.token.value);
    http.send(request_data);

```

**Controller**

```
 public function uploadFile(Request $req)
 {           
   if ($req->hasFile('task_file')) {
         echo 'Request Contains a file';
   } else {
         echo 'No File in Request Object';
   }
 }

```

In response i always get 'No File in Request Object'. What is the correct way of posting file to controller using java script using request\_data. Please help.