title: Dart how to upload image
body: <p>I'm trying to upload an image, here's the code :</p>
  
  <p><strong>server.dart</strong></p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:io';
  
  void main() {
    HttpServer.bind('127.0.0.1', 8080)
      .then((HttpServer server) {
        server.listen((HttpRequest request) {
          if (request.method.toLowerCase() == 'post') {
            request.fold(new BytesBuilder(), (builder, data) =&gt; builder..add(data))
            .then((BytesBuilder builder) {
              File file = new File('abc.jpg');
              file.writeAsBytes(builder.takeBytes(), mode: FileMode.WRITE)
                .then((_) {
                  request.response.close();
                });
            });
          } else {
            File f = new File('test_1.html')
                ..openRead().pipe(request.response);
          }
        });
      });
  }
  </code></pre>
  
  <p><strong>test_1.html</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;test_1&lt;/title&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;form method="post" enctype="multipart/form-data"&gt;
        &lt;input id="fileupload" name="myfile" type="file" placeholder="some file here..."/&gt;
        &lt;input type="submit" /&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then I tried to open the newly saved image using win photo viewer but it says "doesn't support this file format" while I can see the content of the original one. So I'm guessing I'm not using the right method to decode the bytes (maybe, just a guess).</p>
  
  <p>Can you guys give me a hint?</p>
  
  <p>Sorry for the bad english.</p>