title: How to Compress the captured image file size before sending to server using retrofit
body: <p>I am Using Retrofit retrofit:2.1.0' to upload file image to server </p>
  
  <p>If I take image using front camera image get uploaded successfully but if take back side camera its not uploaded i think because of large file size image not uploaded is there any option to compress the file size before sending to server in retrofit?</p>
  
  <p><strong>File Sending Coding</strong></p>
  
  <pre><code>  map.put("complaint_category", RequestBody.create(parse("text"), caty_id_str.getBytes()));
  
      // Map is used to multipart the file using okhttp3.RequestBody
      File file = new File(Config.uriImage);
      // Parsing any Media type file
      RequestBody requestBody = RequestBody.create(parse("*/*"), file);
      MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("photo", file.getName(), requestBody);
      RequestBody filename = RequestBody.create(parse("text/plain"), file.getName());
  
      Call&lt;PostComplaint&gt; call3 = apiInterface.postComplaint(fileToUpload, filename, map);
      call3.enqueue(new Callback&lt;PostComplaint&gt;() {
          @Override
          public void onResponse(Call&lt;PostComplaint&gt; call, Response&lt;PostComplaint&gt; response) {
  
              progressDoalog.dismiss();
  
              PostComplaint respon = response.body();
  
              PostComplaint.Response respo = respon.getResponse();
  
              String result = respo.getResult();
              String data = respo.getData();
              if (result.equalsIgnoreCase("Success")) {
  
                  Toast.makeText(getApplicationContext(), data, Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(Activity_Post_Complaint.this, MainActivity.class);
                  startActivity(intent);
  
              } else {
  
                  Toast.makeText(getApplicationContext(), data, Toast.LENGTH_SHORT).show();
              }
  
          }
  
          @Override
          public void onFailure(Call&lt;PostComplaint&gt; call, Throwable t) {
              progressDoalog.dismiss();
              Log.d("Error", "" + t.getMessage());
              call.cancel();
          }
  
  
      });
  </code></pre>
  
  <p><strong>API Interface</strong></p>
  
  <pre><code>@Multipart
  @POST("/somelink.php?")
  Call&lt;PostComplaint&gt; postComplaint(@Part MultipartBody.Part file,
                                 @Part("photo") RequestBody name,
                                 @PartMap Map&lt;String, RequestBody&gt; fields);
  </code></pre>
  
  <p><strong>APIClient.java</strong></p>
  
  <pre><code>public class APIClient {
  
      private static Retrofit retrofit = null;
  
      static Retrofit getClient() {
  
          HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
          OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor)
                  .connectTimeout(60, TimeUnit.SECONDS)
                  .readTimeout(60, TimeUnit.SECONDS)
                  .writeTimeout(60, TimeUnit.SECONDS)
                  .build();
  
          retrofit = new Retrofit.Builder()
                  .baseUrl("http://192.168.1.135")
                  .addConverterFactory(GsonConverterFactory.create())
                  .client(client)
                  .build();
  
          return retrofit;
      }
  
  }
  </code></pre>