title: Sending a Multipart/form-data POST With JSON File in Kotlin
body: <p>I am trying to send a multipart form with Kotlin in Android Studio:</p>
  <pre><code>class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener {
  { 
  ....
      override fun onCreate(savedInstanceState: Bundle?) {
          uploadPost()
      }
  ....
  }
  
  fun uploadPost() {
      var theJSON = ClockinJSON(&quot;a person&quot;, &quot;a time&quot;, &quot;example@example.com&quot;)
      var myFile = File(getExternalFilesDir(null), &quot;/example.json&quot;)
      var value = theJSON.toString()
      myFile.writeText(value)
      var jsonFileBody: RequestBody = myFile.asRequestBody(&quot;multipart/form-data&quot;.toMediaTypeOrNull())
  
      var pdfFile = File(getExternalFilesDir(null), &quot;/Hello.pdf&quot;)
      var pdfBody = pdfFile.asRequestBody(&quot;multipart/form-data&quot;.toMediaTypeOrNull())
  
      val retrofit = Retrofit.Builder()
          .baseUrl(&quot;https://example.com/&quot;)
          .addConverterFactory(GsonConverterFactory.create())
          .build()
  
      var service = retrofit.create(UploadFile::class.java)
      val call = service.uploadFile(pdfBody, jsonFileBody)
  
      call.enqueue(object : Callback&lt;String&gt; {
          override fun onResponse(call: Call&lt;String&gt;, response: Response&lt;String&gt;) {
              Log.d(&quot;TRACE&quot;, &quot;response is$response&quot;)
          }
  
          override fun onFailure(call: Call&lt;String&gt;, t: Throwable) {
              Log.d(&quot;TRACE&quot;, &quot;didn't work$t&quot;)
              call.cancel()
          }
      })
  }
  
  data class ClockinJSON (
      var clockinTime: String,
      var location: String,
      var companyEmail: String
  )
  
  interface UploadFile {
  @Multipart
  @POST(&quot;mail/&quot;)
  fun uploadFile(
      @Part(&quot;report&quot;) report: RequestBody,
      @Part(&quot;json&quot;) json: RequestBody
  ): Call&lt;String&gt;
  }
  </code></pre>
  <p>Right now I am getting error 500 on the POST request and the server is setup correctly; My Typescript app is sending just fine. I followed the documentation the best I could, and went through all the examples that I can find. Can anyone take a look at let me know what I'm doing wrong here?</p>