title: How can upload image to server with Retrofit on Android
body: <p>In my application, I want to upload image to the server and for this, I used <strong>Retrofit2</strong>.<br></p>
  <p>I write the below codes, but after upload the image shows me a server error!
  <strong>This error is:</strong> Media field is empty, please fill this!</p>
  <p>This error is from my server and says to me the media field is empty!</p>
  <p><strong>My API codes:</strong></p>
  <pre><code>@Multipart
  @POST(&quot;/media&quot;)
  fun uploadImage(
      @Header(AUTHORIZATION) auth: String, @Header(ACCEPT) accept: String, @Header(CONTENT_TYPE) contentType: String,
      @PartMap map: LinkedHashMap&lt;String, RequestBody&gt;
  ): Single&lt;Response&lt;ResponseModelUploadImage&gt;&gt;
  </code></pre>
  <p><strong>My Activity codes:</strong></p>
  <pre><code>            var requestBody: RequestBody
              var body: MultipartBody.Part
              val mapRequestBody = LinkedHashMap&lt;String, RequestBody&gt;()
  
              Log.e(&quot;filePath&quot;,uploadNaturalImageFile.toString())
  
              requestBody = RequestBody.create(MediaType.parse(&quot;multipart/form-data&quot;), uploadNaturalImageFile);
              mapRequestBody.put(&quot;media\&quot;; media=\&quot;&quot; + uploadNaturalImageFile.name, requestBody);
  
              presenter.callUploadImage(userToken, APPLICATION_JSON, APPLICATION_JSON, mapRequestBody)
  </code></pre>
  <p>But when upload this image with Postman, everything is OK and doesn't have any problem!</p>
  <p><strong>Postman request image:</strong><br>
  <a href="https://i.stack.imgur.com/OZaAQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OZaAQ.png" alt="enter image description here" /></a></p>
  <p><strong>UPDATE :</strong> I see my log and show me <code>name=media</code>, but server again media is empty!<br>
  <strong>My logcat messages:</strong></p>
  <pre><code>D/OkHttp: Content-Disposition: form-data; name=&quot;media&quot;; filename=&quot;JPEG_20201108_1623315560915977415445829.jpg&quot;
  </code></pre>
  <p>Why show me this error? how can I fix it?</p>