1.Retrofit接口定义:
@Multipart
@POST(RequestUrl.BANK_CARD_INFO)
Observable<BaseResponse<Object>> bankCardInfo(@Part MultipartBody.Part file);
2.使用:
String traceId = UUID.randomUUID().toString(); //随机生成唯一traceId
String path = selectList.get(0).getPath();
// Log.d(TAG, "onActivityResult: 1616= " + path);
File file = new File(path);
RequestBody fileBody = RequestBody.create(MediaType.parse("image/*"), file);
// RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
RequestBody traceBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
// RequestBody fileRQ = RequestBody.create(MediaType.parse("multipart/form-data"), file);
// MultipartBody.Part part = MultipartBody.Part.createFormData("picture", file.getName(), fileRQ);
Toast.makeText(this, "1933= "+traceId, Toast.LENGTH_SHORT).show();
RequestBody bo=new MultipartBody.Builder()
.addFormDataPart("trace_id",traceId,traceBody)
.addFormDataPart("image",file.getName(),fileBody)
.build();
MultipartBody.Part myBody =
// MultipartBody.Part.createFormData();
MultipartBody.Part.createFormData("image", file.getName(), bo); //name为传递文件的键
//todo:传递银行卡照片到智趣,返回银行卡信息
RxManager.getMethod().bankCardInfo(myBody)
.compose(RxUtil.schedulers(this))
.subscribe(new RxCallback<Object>(this) {
@Override
public void onSuccess(Object o, String msg) {
Log.d(TAG, "onSuccess: 获取银行卡信息成功");
}
});
break;
}
1.定义请求:1个header参数 + 1个请求参数 + 1个文件
2.调用请求:请求参数为文本数据