我正在使用Retrofit Library 1.9.0版本进行Multipart上传。我正在使用以下代码使用Retrofit Library发送多部分数据。这里的一切正常但图像没有反映到数据库中。我试过postman插件那里的东西它工作正常。
public static void userRegistration(Activity activity, String firstName, String lastName, String fatherName, String email, String mobile, String profileName, String password, String confirmPassowrd, String gender, String countryId, String userId, String realpath) {
apiInterface = (ApiInterface) activity;
showDialog(activity);
MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
// MediaType MEDIA_TYPE_PNG = MediaType.parse("multipart/form-data");
File file = null;
// file = new File(uri.toString());
// file = new File(uri.getPath());
file = new File(realpath);
RequestBody requestBody = RequestBody.create(MEDIA_TYPE_PNG, file);
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://example.com/rest_api/index.php/user").build();
Api api = restAdapter.create(Api.class);
api.RegistrationUser(userId, firstName, fatherName, lastName, email, profileName, password, confirmPassowrd, gender, mobile, countryId, requestBody, new Callback<Registration>() {
@Override
public void success(Registration registration, Response response) {
mView.dismiss();
apiInterface.requestCompleted(registration, "registration");
}
@Override
public void failure(RetrofitError error) {
mView.dismiss();
error.printStackTrace();
}
});
}
api方法..
@Multipart
@POST("/registration")
void RegistrationUser(@Part("user_type_id") String uid, @Part("first_name")String fName, @Part("father_name")String father, @Part("last_name")String lName, @Part("email")String mail, @Part("username")String name, @Part("password")String psw, @Part("confirm_password")String cPsw, @Part("gender")String gender, @Part("mobile_number")String phone, @Part("country_id")String cId, @Part("user_image") RequestBody image, Callback<Registration> callback);
我认为我的手术出了问题。请建议我......