title: How to upload file via Retrofit
body: <p>I am trying to upload files from android device to the server using retrofit. </p>
  
  <p>But every time, it results with <code>no</code> in the console.</p>
  
  <p><em>FilesApi.java</em>: </p>
  
  <pre class="lang-java prettyprint-override"><code>public interface FilesApi {
      @Multipart
      @POST("file")
      Call&lt;String&gt; storeFile(@Part MultipartBody.Part file);
  }
  </code></pre>
  
  <p>In <em>MainActivity.java</em>: </p>
  
  <pre class="lang-java prettyprint-override"><code>private void uploadFile(){
       RequestBody requestFile= RequestBody.create(MediaType.parse("multipart/form-data"),file);
      MultipartBody.Part body =
              MultipartBody.Part.createFormData("file", file.getName(), requestFile);
  
  
      //RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),file);
      FilesApi api = RetrofitService.createService(FilesApi.class);
      api.storeFile(body).enqueue(new Callback&lt;String&gt;() {
          @Override
          public void onResponse(Call&lt;String&gt; call, Response&lt;String&gt; response) {
              Log.d(TAG, "onResponse: "+response.body());
          }
  
          @Override
          public void onFailure(Call&lt;String&gt; call, Throwable t) {
              Log.d(TAG, "onFailure: "+t);
          }
      });
  }
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  if(isset($_FILES['file']))
  {
      echo "YESS";
  }
  else
  {
      echo "no";
  }
  ?&gt;
  </code></pre>