Why My Image Is Not Upload In Server And Alwyas Show User Not Register
I'm trying to upload image to server, with android-studio and But I will not succeed Please help me here is my code(all code): java code: in this codes im trying to select picture
Solution 1:
Please update below code.
apiinterface.java
@Multipart@POST("api/register")
Call<responsemodel>registerWithImages(
@Part("fname") RequestBody fname,
@Part("email") RequestBody email,
@Part("number") RequestBody number,
@Part("cname") RequestBody cname,
@Part("intern") RequestBody intern,
@Part("password") RequestBody password,
@Part MultipartBody.Part adharfront,
@Part MultipartBody.Part adharback,
@Part MultipartBody.Part mark,
@Part MultipartBody.Part pass
);
signup.java
privatevoidregisterUserWithImage(){
MediaTypetext= MediaType.parse("text/plain");
RequestBodynameBody= RequestBody.create(text, R_name.getText().toString());
RequestBodyemailBody= RequestBody.create(text, R_email.getText().toString());
RequestBodynumberBody= RequestBody.create(text, R_phone.getText().toString());
RequestBodycnameBody= RequestBody.create(text, spinner.getSelectedItem().getClass().toString());
RequestBodyinternBody= RequestBody.create(text, spinner1.getSelectedItem().getClass().toString());
RequestBodypasswordBody= RequestBody.create(text, R_password.getText().toString());
File file=newFile(filepath);
File file_ab=newFile(filepath);
File file_m=newFile(filepath);
File file_p=newFile(filepath);
File file_pa=newFile(filepath);
RequestBody requestBody= RequestBody.create(MediaType.parse("*/*"), file);
RequestBody requestBody1= RequestBody.create(MediaType.parse("*/*"), file_ab);
RequestBody requestBody2= RequestBody.create(MediaType.parse("*/*"), file_m);
RequestBody requestBody3= RequestBody.create(MediaType.parse("*/*"), file_p);
RequestBody requestBody4= RequestBody.create(MediaType.parse("*/*"), file_pa);
MultipartBody.Part part= MultipartBody.Part.createFormData("adharfront",file.getName(),requestBody);
MultipartBody.Part part1= MultipartBody.Part.createFormData("adharback",file_ab.getName(),requestBody1);
MultipartBody.Part part2= MultipartBody.Part.createFormData("mark",file_m.getName(),requestBody2);
MultipartBody.Part part3= MultipartBody.Part.createFormData("pay",file_p.getName(),requestBody3);
MultipartBody.Part part4= MultipartBody.Part.createFormData("pass",file_pa.getName(),requestBody4);
Retrofit retrofit=ApiClient.getApiClient();
ApiInterface apiInterface=retrofit.create(ApiInterface.class);
Call<responsemodel> responsemodelCall=apiInterface.registerWithImages(
nameBody,
emailBody,
numberBody,
cnameBody,
internBody,
passwordBody,
part,
part1,
part2,
part3,
part4
);
responsemodelCall.enqueue(newCallback<responsemodel>() {
@OverridepublicvoidonResponse(Call<responsemodel> call, Response<responsemodel> response) {
if (response.body()!=null)
{
responsemodel responsemodel= response.body();
Log.i("Response", String.valueOf(responsemodel.isresponse_code()));
if(responsemodel.getStatus().equals("success")){
SharedPreferences sp=getSharedPreferences("credentials",MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putString("adharfront",R_af.getText().toString());
editor.putString("adharback",R_ab.getText().toString());
editor.putString("mark",R_mark.getText().toString());
editor.putString("pay",R_payment.getText().toString());
editor.putString("pass",R_passphoto.getText().toString());
editor.commit();
editor.apply();
}
}
}
@OverridepublicvoidonFailure(Call<responsemodel> call, Throwable t) {
}
});
}
I hope it works for you!
Post a Comment for "Why My Image Is Not Upload In Server And Alwyas Show User Not Register"