本文共 3667 字,大约阅读时间需要 12 分钟。
//上传图片(私有接口) @POST("index.php/PrivateApi/Goods/uploadPic") @Multipart Observable> upLoadImg(@Part MultipartBody.Part parts);
public void upLoadImg(String path) { File file = new File(path); RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); MultipartBody.Part filePart = MultipartBody.Part.createFormData("headimg", file.getName(), requestFile); addDisposable(apiServer.upLoadImg(filePart), new BaseObserver>(baseView, true) { @Override public void onSuccess(BaseListModel o) { baseView.onUpLoadSucc(o.getData()); } @Override public void onError(String msg) { baseView.showError(msg); } }); }
@POST("index.php/PrivateApi/Goods/uploadPic") @Multipart Observable> upLoadImg(@Part MultipartBody.Part[] parts);
public void upLoadImg(ArrayListmedia) { if (media == null) { return; } MultipartBody.Part[] parts = new MultipartBody.Part[media.size()]; int cnt = 0; for (String m : media) { File file = new File(m); RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); MultipartBody.Part filePart = MultipartBody.Part.createFormData("headimg[]", file.getName(), requestFile); parts[cnt] = filePart; cnt++; } addDisposable(apiServer.upLoadImg(parts), new BaseObserver >(baseView, true) { @Override public void onSuccess(BaseListModel o) { baseView.onUpLoadSucc(o.getData()); } @Override public void onError(String msg) { baseView.showError(msg); } }); }
//上传图片(私有接口) @POST("index.php/PrivateApi/Goods/uploadPic") @Multipart Observable> upLoadImg(@Part MultipartBody.Part[] parts, @Part("APP_KEY") RequestBody APP_KEY, @Part("APP_TOKEN") RequestBody APP_TOKEN);
public void upLoadImg(ArrayListmedia) { if (media == null) { return; } MultipartBody.Part[] parts = new MultipartBody.Part[media.size()]; int cnt = 0; for (String m : media) { File file = new File(m); RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); MultipartBody.Part filePart = MultipartBody.Part.createFormData("headimg[]", file.getName(), requestFile); parts[cnt] = filePart; cnt++; } RequestBody appkey = RequestBody.create(MediaType.parse("multipart/form-data"), AppConstant.APP_KEY); RequestBody apptoken = RequestBody.create(MediaType.parse("multipart/form-data"), UserImpl.getAppToken());// addDisposable(apiServer.upLoadImg(parts, appkey, apptoken), new BaseObserver >(baseView, true) { @Override public void onSuccess(BaseListModel o) { baseView.onUpLoadSucc(o.getData()); } @Override public void onError(String msg) { baseView.showError(msg); } }); }
转载地址:http://glizo.baihongyu.com/