在我的应用程序中有两个按钮来选择两个图像。然后两个图像将由另一个上传按钮上传。我正在使用改造来上传图像。但是当我尝试上传时,我无法做到最后一个图像上传了两次。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == PICK_IMAGE_ID) {
// Get the User Selected Image as Bitmap from the static method of ImagePicker class
Bitmap bitmap = ImagePicker.getImageFromResult(this.getActivity(), resultCode, data);
// CALL THIS METHOD TO GET THE ACTUAL PATH
panImg = new File(getRealPathFromURI(tempUri));
}
if(requestCode == PICK_IMAGE){
// Get the User Selected Image as Bitmap from the static method of ImagePicker class
Bitmap bitmap = ImagePicker.getImageFromResult(this.getActivity(), resultCode, data);
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = getImageUri(getContext(), bitmap);
// CALL THIS METHOD TO GET THE ACTUAL PATH
idImg = new File(getRealPathFromURI(tempUri));
}
if (requestCode == PICK_IMG){
// Get the User Selected Image as Bitmap from the static method of ImagePicker class
Bitmap bitmap = ImagePicker.getImageFromResult(this.getActivity(), resultCode, data);
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = getImageUri(getContext(), bitmap);
// CALL THIS METHOD TO GET THE ACTUAL PATH
bankImg = new File(getRealPathFromURI(tempUri));
}
}
}
这是api调用。
MultipartBody.Part filePart = null;
MultipartBody.Part filePart1=null;
if (panImg != null){
filePart1 = MultipartBody.Part.createFormData("pan_img",panImg.getName(),RequestBody.create(MediaType.parse("image/*"),panImg));
}
if (idImg != null){
filePart = MultipartBody.Part.createFormData("id_img",idImg.getName(),RequestBody.create(MediaType.parse("image/*"),idImg));
}
Call<KycData> call2 = APIClient.getInstance()
.updatekyc(
filePart1,
filePart
);
请帮助我。
答案 0 :(得分:0)
您没有为onActivityResult
请求代码向PICK_IMAGE_ID
中的 tempUri 分配值。因此,如果条件为onActivityResult
,则它使用的是您从其他分配的值