0

I'm trying to upload some data to the API using form-data request type. I used the @Multipart annotation in the retrofit interface and @Part in the fields. But server is throwing the error. Okhttp code for the same is working fine.

 OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("content", “save this text”)
  .addFormDataPart(“id”, “111”)
  .build();
Request request = new Request.Builder()
  .url("https://myurl”)
  .method("POST", body)
  .addHeader("Authorization", "Bearer token”)
  .build();
Response response = client.newCall(request).execute();

How can we do the same with Retrofit?

Manu Ram V
  • 369
  • 1
  • 3
  • 23
  • Where's your Retrofit part code? Please [edit] the question and post it here. – Shashanth Jun 14 '20 at 06:09
  • @Shashanth Can you help? https://stackoverflow.com/questions/62783444/why-does-multipart-pdf-is-not-able-to-upload-in-api-using-retrofit-2-in-android?noredirect=1#comment111031344_62783444 – Priyanka Singh Jul 08 '20 at 07:27

0 Answers0