android - 发送列表有问题上传文件到服务器改造时
问题描述
接口接口.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);
问题是这个只有 RequestBody 只接受 File、byte[]、String、ByteString 我如何发送带有@part 的 List 真正的问题是这个。谢谢你的帮助。
解决方案
推荐阅读
- python - 为什么在对回归进行正则化时会跳过 theta0?
- java - 如果 RecyclerView 中的条件为 onBindViewHolder
- java - JAVA使用构造函数创建了每个类的两个具有完整数据的对象,但出现错误
- r - 将共享数据列中的多个值重新编码/替换为跨数据帧的单个值
- audio-recording - 如何使用 IAudioCaptureClient 录制立体声音频数据?
- c# - MySql 字符编码问题——货币符号(¤)
- php - 使用 MOVE_TO_FILE 将文件输入插入 BD
- javascript - 使用 document.execCommand("copy") 复制电子邮件地址
- amazon-web-services - boto3 s3 generate_presigned_url ExpiresIn 无法按预期工作
- solr - SOLR 邻近搜索提升不同斜率