I am new for Retrofit I wanna to upload single image with different params like name,dob,mobile. i don't know where i am wrong Please guide me. I follow this LINK
Here is my code
interface
@Multipart
@POST("signup")
Call<ResponseBody> getSignup(@Part("name") RequestBody name, @Part("email") RequestBody email, @Part("dob") RequestBody dob, @Part("phone") RequestBody phone, @Part("IMEI") RequestBody IMEI, @Part MultipartBody.Part file);
upload code
// create RequestBody instance from file
RequestBody requestFile =
RequestBody.create(MediaType.parse("multipart/form-data"), file);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body =
MultipartBody.Part.createFormData("image", file.getName(), requestFile);
RequestBody name =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_name.getText().toString());
RequestBody email =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_email.getText().toString());
RequestBody dob =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_dob.getText().toString());
RequestBody mobile =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_mobile.getText().toString());
RequestBody imei =
RequestBody.create(
MediaType.parse("multipart/form-data"), IMEI);
Call<ResponseBody> responseBodyCall = apiInterface.getSignup(name, email, dob, mobile, imei, body);
responseBodyCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
String response_two = response.body().toString();
Log.i(TAG, "onResponse: " + response_two);
// startActivity(new Intent(this, OTPActivity.class));
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e("Upload error:", t.getMessage());
}
});