title: How to pass request string param using Retrofit for file Upload?
body: <p>How to send the request string param using Retrofit. I have submitted the code below. Here how to add the string param and send to server. </p>
  
  <p>AppConfig:</p>
  
  <hr>
  
  <p>public class AppConfig {</p>
  
  <pre><code>public static String BASE_URL = "http://104.239.173.64/peoplecaddie-api";
  
  public static Retrofit getRetrofit() {
  
      return new Retrofit.Builder()
              .baseUrl(AppConfig.BASE_URL)
              .addConverterFactory(GsonConverterFactory.create())
              .build();
  }
  </code></pre>
  
  <p>ApiConfig:</p>
  
  <pre><code>public interface ApiConfig {
  
      @Multipart
      @POST("/general/Candidate/fileUpload")
      Call&lt;ServerResponse&gt; upload(
              @Header("Authorization") String authorization,
              @PartMap Map&lt;String, RequestBody&gt; map
      );
  }
  </code></pre>
  
  <p>ServerResponse:</p>
  
  <hr>
  
  <pre><code>public class ServerResponse {
  
      // variable name should be same as in the json response from php
      @SerializedName("success")
      boolean success;
      @SerializedName("message")
      String message;
  
      public String getMessage() {
          return message;
      }
  
      public boolean getSuccess() {
          return success;
      }
  
  }
  </code></pre>
  
  <h2>MainActivity:</h2>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      Button btnUpload, btnPickImage, btnPickVideo;
      String mediaPath;
      ImageView imgView;
      String[] mediaColumns = {MediaStore.Video.Media._ID};
      ProgressDialog progressDialog;
      /**
       * ATTENTION: This was auto-generated to implement the App Indexing API.
       * See https://g.co/AppIndexing/AndroidStudio for more information.
       */
      private GoogleApiClient client2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          progressDialog = new ProgressDialog(this);
          progressDialog.setMessage("Uploading...");
  
          btnUpload = (Button) findViewById(R.id.upload);
          btnPickImage = (Button) findViewById(R.id.pick_img);
          btnPickVideo = (Button) findViewById(R.id.pick_vdo);
          imgView = (ImageView) findViewById(R.id.preview);
  
          btnUpload.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  uploadFile();
              }
          });
  
          btnPickImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                          MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                  startActivityForResult(galleryIntent, 0);
              }
          });
  
          // Video must be low in Memory or need to be compressed before uploading...
          btnPickVideo.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                          MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
                  startActivityForResult(galleryIntent, 1);
              }
          });
  
          // ATTENTION: This was auto-generated to implement the App Indexing API.
          // See https://g.co/AppIndexing/AndroidStudio for more information.
          client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          try {
              // When an Image is picked
              if (requestCode == 0 &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
  
                  // Get the Image from data
                  Uri selectedImage = data.getData();
                  String[] filePathColumn = {MediaStore.Images.Media.DATA};
  
                  Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                  assert cursor != null;
                  cursor.moveToFirst();
  
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  mediaPath = cursor.getString(columnIndex);
                  // Set the Image in ImageView for Previewing the Media
                  imgView.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
                  cursor.close();
  
              } // When an Video is picked
              else if (requestCode == 1 &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
  
                  // Get the Video from data
                  Uri selectedVideo = data.getData();
                  String[] filePathColumn = {MediaStore.Video.Media.DATA};
  
                  Cursor cursor = getContentResolver().query(selectedVideo, filePathColumn, null, null, null);
                  assert cursor != null;
                  cursor.moveToFirst();
  
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  mediaPath = cursor.getString(columnIndex);
                  // Set the Video Thumb in ImageView Previewing the Media
                  imgView.setImageBitmap(getThumbnailPathForLocalFile(MainActivity.this, selectedVideo));
                  cursor.close();
  
              } else {
                  Toast.makeText(this, "You haven't picked Image/Video", Toast.LENGTH_LONG).show();
              }
          } catch (Exception e) {
              Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
          }
  
      }
  
      // Providing Thumbnail For Selected Image
      public Bitmap getThumbnailPathForLocalFile(Activity context, Uri fileUri) {
          long fileId = getFileId(context, fileUri);
          return MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),
                  fileId, MediaStore.Video.Thumbnails.MICRO_KIND, null);
      }
  
      // Getting Selected File ID
      public long getFileId(Activity context, Uri fileUri) {
          Cursor cursor = context.managedQuery(fileUri, mediaColumns, null, null, null);
          if (cursor.moveToFirst()) {
              int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
              return cursor.getInt(columnIndex);
          }
          return 0;
      }
  
      // Uploading Image/Video
      private void uploadFile() {
          progressDialog.show();
  
          // Map is used to multipart the file using okhttp3.RequestBody
          Map&lt;String, RequestBody&gt; map = new HashMap&lt;&gt;();
          File file = new File(mediaPath);
          RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
          map.put("fileContent0\"; filename=\"" + file.getName() + "\"", requestBody);
  
         ApiConfig getResponse = AppConfig.getRetrofit().create(ApiConfig.class);
          Call&lt;ServerResponse&gt; call = getResponse.upload(token, map);
          call.enqueue(new Callback&lt;ServerResponse&gt;() {
              @Override
              public void onResponse(Call&lt;ServerResponse&gt; call, Response&lt;ServerResponse&gt; response) {
                  ServerResponse serverResponse = response.body();
                  if (serverResponse != null) {
                      if (serverResponse.getSuccess()) {
                          Log.e("Response", serverResponse.getMessage());
                          Toast.makeText(getApplicationContext(), serverResponse.getMessage(), Toast.LENGTH_SHORT).show();
                      } else {
                          Log.e("Response", serverResponse.getMessage());
                          Toast.makeText(getApplicationContext(), serverResponse.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  } else {
                      Log.v("Response", serverResponse.toString());
                  }
                  progressDialog.dismiss();
              }
  
              @Override
              public void onFailure(Call&lt;ServerResponse&gt; call, Throwable t) {
                  Log.e("Throwable", t.toString());
              }
          });
      }
  
  
  
      @Override
      public void onStart() {
          super.onStart();
  
          // ATTENTION: This was auto-generated to implement the App Indexing API.
          // See https://g.co/AppIndexing/AndroidStudio for more information.
          client2.connect();
          Action viewAction = Action.newAction(
                  Action.TYPE_VIEW, // TODO: choose an action type.
                  "Main Page", // TODO: Define a title for the content shown.
                  // TODO: If you have web page content that matches this app activity's content,
                  // make sure this auto-generated web page URL is correct.
                  // Otherwise, set the URL to null.
                  Uri.parse("http://host/path"),
                  // TODO: Make sure this auto-generated app URL is correct.
                  Uri.parse("android-app://com.delaroystudios.androidupload/http/host/path")
          );
          AppIndex.AppIndexApi.start(client2, viewAction);
      }
  
      @Override
      public void onStop() {
          super.onStop();
  
          // ATTENTION: This was auto-generated to implement the App Indexing API.
          // See https://g.co/AppIndexing/AndroidStudio for more information.
          Action viewAction = Action.newAction(
                  Action.TYPE_VIEW, // TODO: choose an action type.
                  "Main Page", // TODO: Define a title for the content shown.
                  // TODO: If you have web page content that matches this app activity's content,
                  // make sure this auto-generated web page URL is correct.
                  // Otherwise, set the URL to null.
                  Uri.parse("http://host/path"),
                  // TODO: Make sure this auto-generated app URL is correct.
                  Uri.parse("android-app://com.delaroystudios.androidupload/http/host/path")
          );
          AppIndex.AppIndexApi.end(client2, viewAction);
          client2.disconnect();
      }
  }
  </code></pre>
  
  <p>In the above example code just passed the token and File with the help of request Body. </p>
  
  <ul>
  <li>How to send request string param with above code.</li>
  </ul>
  
  <p>that is How to send Below  login_params details as a request param using retrofit. when i tried i got 
  /Throwable: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ . this exception.</p>
  
  <pre><code>  HashMap&lt;String, String&gt; login_params = new HashMap&lt;String, String&gt;();
          login_params.put("fileCount", "1");
          login_params.put("id","1743");
          login_params.put("fileType", "SAMPLE");
          login_params.put("platform", "Android");
          login_params.put("externalID", "portpolio");
  </code></pre>