title: Flutter sending a post request to a Django API with a file as the body
body: <p>I have a Django API where a user is able to upload a file through a post request with the following body:</p>
  <pre><code>{
    &quot;file&quot;: *attached file*
  }
  </code></pre>
  <p>In Django, the file is gathered from the request with <code>request.FILES['file']</code></p>
  <p>The request has to be sent from flutter (dart) code. I have tried a few ways, this is the function from my latest attempt which shows an error - because the &quot;file&quot; is not in the correct format.</p>
  <pre><code>static void uploadProfilePhoto(File file, String fileId) async {
      Uint8List fileBytes = file.readAsBytesSync();
      var response = http.post(
        globals.baseURL() + &quot;/upload/&quot;,
        //headers: {&quot;Content-Type&quot;: &quot;application/json&quot;},
        body: {
          &quot;file&quot;:base64Encode(fileBytes)
        }
      ).then((v)=&gt;print(&quot;v: &quot;+v.body));
    }
  </code></pre>
  <p>Any idea in what format the &quot;file&quot; should be sent from flutter? Else is there any other method which might work? Thank you in advance.</p>