将文件上传到服务器时发送List <integer>时遇到问题

时间:2019-05-02 12:49:00

标签: android retrofit retrofit2

ApiInterface.java

public interface ApiInterface {
@Multipart
@POST("/register")
  registerUser(
@Part("first_name") RequestBody firstname,
@Part("last_name") RequestBody lastname, 
@Part("email") RequestBody email,
@Part MultipartBody.Part photo,
@Part("types") List<Integer> types);  ->This part I am     having    problem
}

Presenter.java

public void registerUser(String firstname, String lastname,   String emails, String passwords, File profilePhoto,   List<Integer> eventTagPks ) {
    MultipartBody.Part partProfilePhoto =    MultipartBody.Part.createFormData("profile_photo", profilePhoto.getName(), RequestBody.create(MediaType.parse("image/*"), profilePhoto));
    RequestBody name = RequestBody.create(MediaType.parse("multipart/form-data"),firstname);
    RequestBody surname = RequestBody.create(MediaType.parse("multipart/form-data"),lastname);
    RequestBody email = RequestBody.create(MediaType.parse("multipart/form-data"),emails);
    RequestBody birthdate = RequestBody.create(MediaType.parse("multipart/form-data"),birthday);
    RequestBody password = RequestBody.create(MediaType.parse("multipart/form-data"),passwords);
    //RequestBody eventTagPkList = RequestBody.create(MediaType.parse("multipart/form-data"), eventTagPks); ->I cannot create RequestBody that contains Integer List


    apiInterface.registerUser(name,surname,email,password,birthdate,partProfilePhoto,eventTagPks).enqueue(new CustomCallBack<RegisterResponse>(activity,null,registerView,CustomCallBack.Type.None) {
        @Override
        public void onResponse(@NonNull Call<RegisterResponse> call, @NonNull Response<RegisterResponse> response) {
            super.onResponse(call, response);
            if (response.isSuccessful()) {

            }
        }

        @Override
        public void onFailure(@NonNull Call<RegisterResponse> call, @NonNull Throwable t) {
            super.onFailure(call, t);
        }
    });
}

问题
我无法创建包含整数列表的RequestBody

RequestBody eventTagPkList = RequestBody.create(MediaType.parse("multipart/form-data"), eventTagPks);      

问题是这是Only RequestBody仅接受File,byte [],String,ByteString 我该如何使用@part发送列表,真正的问题是这个。谢谢您的帮助。

0 个答案:

没有答案