0

I am trying to get string value returned by API on success. I am getting success but I do not getting the required value in the response, but when I navigate to response-> body-> responseBody then it shows me that value but I am unable to get that value (please check screen shot for detail).

private void uploadImage(String imagePath) {

    try{
        showProgressDialogue();
        File file = new File(imagePath);
        RequestBody photoContent = RequestBody.create(MediaType.parse("multipart/form data"), file);
        MultipartBody.Part photo = MultipartBody.Part.createFormData("file",file.getName(),photoContent);
        //RequestBody description = RequestBody.create(MediaType.parse("description"),"abc");
        UploadService uploadService = APIClient.getClient().create(UploadService.class);
        Call call1 = uploadService.UploadOMRExamPaper(photo);
        call1.enqueue(new Callback<Response>() {
            @Override
            public void onResponse(Call<Response> call, Response<Response> response) {
                progressBar.dismiss();
            }

            @Override
            public void onFailure(Call<Response> call, Throwable t) {
                progressBar.dismiss();
                Toast.makeText(getApplicationContext(), t.getMessage(),Toast.LENGTH_LONG).show();
            }
        });

    }catch (Exception e){
        progressBar.dismiss();
        Toast.makeText(this, e.getMessage(),Toast.LENGTH_LONG).show();
    }

}

enter image description here

ejderuby
  • 710
  • 5
  • 21

1 Answers1

0

Change your code:

From:

File file = new File(imagePath);
RequestBody photoContent = RequestBody.create(MediaType.parse("multipart/form data"), file);
MultipartBody.Part photo = MultipartBody.Part.createFormData("file",file.getName(),photoContent);

To:

File file = new File(imagePath);
RequestBody photoContent = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part photo = MultipartBody.Part.createFormData("upload", file.getName(), photoContent );

Note:"upload" is just example here,you should write there from your api paramater.

Kabir
  • 852
  • 7
  • 11