title: How to send image through post using JSON in flutter?
body: <p>I am building a flutter app, which utilizes <a href="https://pub.dartlang.org/packages/image_picker" rel="noreferrer">image picker</a> to capture or select an image from the gallery, but I am having a hard time how to POST that image to my server from the client side.</p>
  
  <p>From what I gathered, I can send the local image via JSON by converting an image file to bytes and then sending it as BASE64. </p>
  
  <pre><code>import 'dart:convert';
  import 'package:crypto/crypto.dart';
  
  Future&lt;Map&gt; _avatarSubmit() async {
      String url = api + '/api/account';
      http.Response response = await http.post(Uri.encodeFull(url), headers: {
        "Accept": "application/json",
        "Cookie": "MYCOOKIE=" + sessionCookie2 + "; MYTOKENS=" + sessionCookie3,
        "Content-type": "multipart/form-data",
      }, body: {
        "image": "",
      });
      Map content = JSON.decode(response.body);
      return content;
    }
  </code></pre>
  
  <p>My question is how to convert an image file in the device into bytes, so I can then use <a href="https://pub.dartlang.org/packages/image_picker" rel="noreferrer">crypto</a> plugin to convert it to BASE64?</p>
  
  <p>Thank you in advance.</p>