retrofit 同时上传文件和参数

RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"),
new File("/mnt/sdcard/Pictures/testhead.png"));
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "testhead.png", fileBody)
.addFormDataPart("address", "test address")
.build();
HttpUtils.getHttpService().updateMyInfo(requestBody)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new ProgressSubscriber<Object>(mContext, mView) {
@Override
public void onSuccess(Object o) {
mView.onAddCheckSuccess();
}
});
posted @ 2021-04-08 17:27  Jokeyyu  阅读(902)  评论(0编辑  收藏  举报