title: Flutter Multipart Request with headers and other fields
body: <p>I want to send a Multipart request to my server like following :</p>
  <pre><code>{
    &quot;file&quot; : some_file.jpg,
    &quot;room&quot; : {
               &quot;roomName&quot; : &quot;Room Name&quot;
             }
  }
  </code></pre>
  <p>I have certain headers</p>
  <pre><code>{
    &quot;authorisation&quot; : &quot;Basic header&quot;
    &quot;screenInfo&quot; : &quot;screenInfo&quot;,
    &quot;operation&quot; : &quot;operation&quot;,
    &quot;userId&quot; : &quot;integer&quot;,
  }
  </code></pre>
  <p>I have tried http.Multipart request as well as Dio package, but I am unable to send the request properly</p>
  <p>What I have Used :</p>
  <ol>
  <li><p><strong>http.MultipartRequest</strong></p>
  <pre><code>final length = _mWebRequest.getRequestFiles()[&quot;file&quot;].lengthSync();
  print(&quot;Length : $length&quot;);
   var request = http.MultipartRequest('POST', Uri.parse(urlString))
     ..headers.addAll(_mWebRequest.getHeaders())
     ..fields.addAll(_mWebRequest.getRequestParam())
     ..files.add(
       http.MultipartFile.fromBytes('file',
           _mWebRequest.getRequestFiles()[&quot;file&quot;].readAsBytesSync(),
           filename: _mWebRequest
               .getRequestFiles()[&quot;file&quot;]
               .path
               .split(&quot;/&quot;)
               .last),
     );
  </code></pre>
  </li>
  <li><p><strong>Dio package</strong></p>
  <pre><code>Dio dio = new Dio();
   var formData = FormData.fromMap({
     &quot;room&quot;: {&quot;roomName&quot;: &quot;Custom Room 1&quot;, &quot;isDefault&quot;: &quot;false&quot;},
     &quot;file&quot;: await MultipartFile.fromFile(
         _mWebRequest.getRequestFiles()[&quot;file&quot;].path,
         filename:
             _mWebRequest.getRequestFiles()[&quot;file&quot;].path.split(&quot;/&quot;).last)
   });
   dio.options.headers.addAll(_mWebRequest.getHeaders());
   var response = await dio.post(urlString, data: formData);
  </code></pre>
  </li>
  </ol>
  <p>Can someone help me out ?</p>