title: How to upload image using http?
body: <p>I am trying to upload image using Flutter's http plugin.</p>
  
  <p>Following is my code</p>
  
  <pre><code>Future&lt;ImageUploadModel&gt; postImage(File photoPath) async {
      ImageUploadModel imageUploadModel;
  
      var request = http.MultipartRequest(
          "POST", Uri.parse("my_api_url"));
  
      request.files.add(http.MultipartFile.fromBytes(
          "photo", await File.fromUri(Uri.parse(photoPath.path)).readAsBytes(),
          contentType: MediaType('image', 'jpg')));
  
      final response = await request.send();
  
      Uint8List responseByteArray = await response.stream.toBytes();
  
  return standardSerializers.deserializeWith(ImageUploadModel.serializer, json.decode(utf8.decode(responseByteArray)));
    }
  </code></pre>
  
  <p>I tried uploading image using Postman and the image get uploaded properly. </p>
  
  <p>I have followed the links on stack but I am not able to resolve the error </p>
  
  <p><a href="https://stackoverflow.com/questions/49125191/flutter-http-post-upload-an-image">Flutter: http post upload an image</a>
  <a href="https://stackoverflow.com/questions/52501529/flutter-how-to-send-multiple-files-to-http-post">Flutter how to send multiple files to http post</a>
  <a href="https://stackoverflow.com/questions/51161862/how-to-send-an-image-to-an-api-in-dart-flutter">How to send an image to an api in dart/flutter?</a>
  <a href="https://stackoverflow.com/questions/44841729/how-to-upload-image-in-flutter">How to upload image in Flutter?</a></p>
  
  <p>I am getting a status code of 200 but when I tried to access any variable from the response I get empty string.</p>
  
  <p>I tried with Native Android using Kotlin and Retrofit and it works properly</p>
  
  <p>I also tried the <code>Dio</code> library</p>
  
  <pre><code>Dio dio = Dio();
      FormData formdata = FormData();
  
      formdata.add("photo", UploadFileInfo(photoPath, basename(photoPath.path)));
      dio
          .post("My_API_URL",
              data: formdata,
              options: Options(
                  method: 'POST',
                  responseType: ResponseType.json // or ResponseType.JSON
                  ))
          .then((response) {
        print("2 $response");
        return standardSerializers.deserializeWith(
            ImageUploadModel.serializer, json.decode(response.data));
      }).catchError((error) =&gt; print("3 $error"));
  </code></pre>
  
  <p>I don't want to convert my image to base64</p>