没有改造注释#1

时间:2017-04-01 11:12:17

标签: android android-layout android-volley retrofit retrofit2

我正在尝试使用retrofit 2.0发布帖子请求,其中还有要发送的图像,但每次我尝试我都会收到一条错误,说没有找到改装注释...请帮我解决这个问题...会非常谢天谢地..以下是我的代码片段

MY RETROFIT INTERFACE

 @Multipart
    @POST("empowerapp/seekerreg.php")
    Call<ResponseModel> registerSeeker(@Part MultipartBody.Part image,
                                       @Part("fname") RequestBody fname,
                                       @Part("fname") RequestBody lname,
                                       @Part("promoter") RequestBody promoter,
                                       @Part("dob") RequestBody dob,
                                       @Part("gender") RequestBody gender,
                                       @Part("paswd") RequestBody paswd,
                                       @Part("ph") RequestBody phone,
                                       @Part("email") RequestBody email,
                                       @Part("weight") RequestBody weight,
                                       @Part("height") RequestBody height,
                                       @Part("qualification") RequestBody qualification,
                                       @Part("color") RequestBody color,
                                       @Part("lang_known") RequestBody languages,
                                       @Part("experience") RequestBody experience,
                                       @Part("exp_type") RequestBody exptype,
                                       @Part("dres_code") RequestBody dresscode,
                                       @Part("vehicle_mode") RequestBody vehicleMode,
                                       @Part("photo1") RequestBody photo1,
                                       @Part("photo2") RequestBody photo2,
                                       @Part("photo3") RequestBody photo3,
                                       @Part("address") RequestBody address,
                                       @Part("landmark") RequestBody landmark,
                                       @Part("location") RequestBody location,
                                       @Part("city") RequestBody city,
                                       @Part("state") RequestBody state,
                                       @Part("contry") RequestBody contry,
                                       @Part("pincode") RequestBody pincode,
                                       @Part("bank_name") RequestBody bankName,
                                       @Part("ac_name") RequestBody acName,
                                       @Part("ac_number") RequestBody acNumber,
                                       @Part("ifsc") RequestBody ifsc,
                                       @Part("br_name") RequestBody brName,
                                       @Part("size") RequestBody size);

我的改装电话方法

public void registerSeeker(SeekerProfileModel profileModel) {

        System.out.println("###exp" + s_exp.getText().toString());

        //create file which we want to send to server.
        File imageFIle = new File(selectedIdproofPath);

        //request body is used to attach file.
        RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),imageFIle);

        //and request body and file name using multipart.
        MultipartBody.Part selectedIdproof = MultipartBody.Part.createFormData("id_proof", imageFIle.getName(),requestBody); //"image" is parameter for photo in API.


        RequestBody promoter = RequestBody.create(MediaType.parse("text/plain"),profileModel.getPromoter() );
        RequestBody fname = RequestBody.create(MediaType.parse("text/plain"),profileModel.getFname());
        RequestBody lname = RequestBody.create(MediaType.parse("text/plain"),profileModel.getLname());
        RequestBody email = RequestBody.create(MediaType.parse("text/plain"), profileModel.getEmail());
        RequestBody phone = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPhone());
        RequestBody languages = RequestBody.create(MediaType.parse("text/plain"), profileModel.getLanguages());
        RequestBody address = RequestBody.create(MediaType.parse("text/plain"), profileModel.getAddress());
        RequestBody landmark = RequestBody.create(MediaType.parse("text/plain"),profileModel.getLandmark());
        RequestBody city = RequestBody.create(MediaType.parse("text/plain"),profileModel.getCity());
        RequestBody state = RequestBody.create(MediaType.parse("text/plain"), profileModel.getState());
        RequestBody contry = RequestBody.create(MediaType.parse("text/plain"), profileModel.getContry());
        RequestBody pincode = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPincode());
        RequestBody paswd = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPassword());
        RequestBody dob = RequestBody.create(MediaType.parse("text/plain"), profileModel.getDob());
        RequestBody gender = RequestBody.create(MediaType.parse("text/plain"), profileModel.getGender());

        RequestBody exp = RequestBody.create(MediaType.parse("text/plain"), profileModel.getExperience());
        RequestBody weight = RequestBody.create(MediaType.parse("text/plain"), profileModel.getWeight());
        RequestBody expType = RequestBody.create(MediaType.parse("text/plain"), profileModel.getExperienceType());
        RequestBody qualification = RequestBody.create(MediaType.parse("text/plain"), profileModel.getQualification());
        RequestBody color = RequestBody.create(MediaType.parse("text/plain"), profileModel.getColor());

        RequestBody size = RequestBody.create(MediaType.parse("text/plain"), profileModel.getSize());
        RequestBody height = RequestBody.create(MediaType.parse("text/plain"), profileModel.getHeight());
        RequestBody dresscode = RequestBody.create(MediaType.parse("text/plain"), profileModel.getDressCode());
        RequestBody vehicleMode = RequestBody.create(MediaType.parse("text/plain"), profileModel.getVehicleMode());
        RequestBody photo1 = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPhoto1());
        RequestBody photo2 = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPhoto2());
        RequestBody photo3 = RequestBody.create(MediaType.parse("text/plain"), profileModel.getPhoto3());
        RequestBody bankname = RequestBody.create(MediaType.parse("text/plain"), profileModel.getBankName());
        RequestBody branchname = RequestBody.create(MediaType.parse("text/plain"), profileModel.getBranchName());
        RequestBody acccountnumber = RequestBody.create(MediaType.parse("text/plain"), profileModel.getAccontNumber());
        RequestBody ifsc = RequestBody.create(MediaType.parse("text/plain"), profileModel.getIfsc());
        RequestBody accountholder = RequestBody.create(MediaType.parse("text/plain"), profileModel.getAccountName());

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Allconstants.MAIN_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        RetrofitInterface service = retrofit.create(RetrofitInterface.class);

        Call<ResponseModel> call = service.registerSeeker(selectedIdproof,fname,lname,promoter,dob,gender,paswd,phone,email,weight,height,qualification,color,languages,exp,expType,dresscode,vehicleMode,photo1,photo2,photo3,address,landmark,landmark,city,state,contry,pincode,bankname,accountholder,acccountnumber,ifsc,branchname,size
                );
        call.enqueue(new Callback<ResponseModel>() {
            @Override
            public void onResponse(Response<ResponseModel> response, Retrofit retrofit) {
                System.out.println("###coming" + response.body().getStatus());
                pd.dismiss();
                if (response.body().getStatus().equalsIgnoreCase("Success"))
                {
                    pd.dismiss();
                    loginSession.createLoginSession(Allconstants.SEEKER,Allconstants.S_REG_ACTIVITY,response.body().getName(), response.body().getId());
                    Toast.makeText(Registration.this,"successfully registered",Toast.LENGTH_LONG).show();
                    System.out.println("###coming"+response.body().toString());
                }else{
                    pd.dismiss();
                    Toast.makeText(Registration.this,"oops!!!something went wrong..try again"+response.body().getStatus(),Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(Throwable t) {
                pd.dismiss();
                Toast.makeText(Registration.this, t.getStackTrace().toString(), Toast.LENGTH_LONG).show();
                System.out.println("###error1" + t.getMessage());
                System.out.println("###stack trace: ");
                t.printStackTrace();
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

对于第一个参数

检查此代码

ngModel

你有File file = new File(filePath); RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file); MultipartBody.Part body = MultipartBody.Part.createFormData("upload",file.getName(), reqFile); 尝试以上内容。你需要使用文件提供程序,要安全地从你的应用程序提供文件到另一个应用程序,你需要配置你的应用程序以提供文件的安全句柄,内容URI的形式。 Android FileProvider组件根据您在XML中提供的规范生成文件的内容URI。

为您的应用定义FileProvider需要清单中的条目。此条目指定用于生成内容URI的权限,以及指定应用程序可以共享的目录的XML文件的名称。

MediaType.parse("multipart/form-data")

}

然后调用该函数将文件暴露给fileprovider以获取路径。

 String mCurrentPhotoPath;

 private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new  Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
    imageFileName,  /* prefix */
    ".jpg",         /* suffix */
    storageDir      /* directory */
);

// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;