title: How to decrease size of an multiple images in Retrofit
body: <p>I'm trying to upload multiple images to server using Retrofit, While I upload small images no problem at all but if I upload large images it's get timeout error. Here is my code</p>
  
  <pre><code>  File file1 = new File(getRealPathFromDocumentUri(this, selected.get(0)));
    File file2 = new File(getRealPathFromDocumentUri(this, selected.get(1)));
    RequestBody reqFile1 = RequestBody.create(MediaType.parse("image/*"), file1);
    RequestBody reqFile2 = RequestBody.create(MediaType.parse("image/*"), file2);
    MultipartBody.Part body1 = MultipartBody.Part.createFormData("image1", file1.getName(), reqFile1);
    MultipartBody.Part body2 = MultipartBody.Part.createFormData("image2", file1.getName(), reqFile2);
  
      RequestBody premium1 = RequestBody.create(MediaType.parse("text/plain"), premium);
      RequestBody featured1 = RequestBody.create(MediaType.parse("text/plain"), featured);
  
  
      Call&lt;ResponseBody&gt; call = api.getPostedResult(premium1, featured1, body1, body2);
      call.enqueue(new Callback&lt;ResponseBody&gt;() {
          @Override
          public void onResponse(Call&lt;ResponseBody&gt; call, Response&lt;ResponseBody&gt; response) {
              //  pb.dismiss();utils
              utils.dismissProgress();
              if (response.code() == 200) {
  
  
                  Toast.makeText(getApplicationContext(), "Your AD Have been Posted Sucessfully", Toast.LENGTH_LONG).show();
                  Intent intent = null;
                  intent = new Intent(getApplicationContext(), LandingPage.class);
                  startActivity(intent);
  
  
              } else {
  
                  Toast.makeText(getApplicationContext(), "" + response.code(), Toast.LENGTH_LONG).show();
              }
          }
  
          @Override
          public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
              //
              utils.dismissProgress();
              Toast.makeText(getApplicationContext(), "" + t.getMessage(), Toast.LENGTH_LONG).show();
          }
      });
  </code></pre>
  
  <p>and I'm getting file path using my List selected and sending it to below code, Please help me with this, I  want to know how to decrease image size and send it to server in Multipart.body  </p>
  
  <pre><code>     public static String getRealPathFromDocumentUri(Context context, Uri uri) {
      String filePath = "";
  
      Pattern p = Pattern.compile("(\\d+)$");
      Matcher m = p.matcher(uri.toString());
      if (!m.find()) {
          //    Log.e(ImageConverter.class.getSimpleName(), "ID for requested image not found: " + uri.toString());
          return filePath;
      }
      String imgId = m.group();
  
      String[] column = {MediaStore.Images.Media.DATA};
      String sel = MediaStore.Images.Media._ID + "=?";
  
      Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              column, sel, new String[]{imgId}, null);
  
      int columnIndex = cursor.getColumnIndex(column[0]);
  
      if (cursor.moveToFirst()) {
          filePath = cursor.getString(columnIndex);
      }
      cursor.close();
  
      return filePath;
  }
  </code></pre>