【android 使用Retrofit2 RxJava 文件上传】登山则情满于山,观海则意溢于海。这篇文章主要讲述android 使用Retrofit2 RxJava 文件上传相关的知识,希望能为你提供帮助。
private static void upload(final Context context, final int type, File logFile) { Map< String, RequestBody> map = new HashMap< > (); if (logFile != null & & logFile.length() > 0) { map.put(parseMapKey("file", logFile.getName()), parseRequestBody(logFile)); }ApiFactory.getInstance().getApiService().uploadLog(map) .compose(RxSchedulers.< List< String> > combine()) .subscribe(new RxSubscriber1< List< String> > () { @Override public void onError(ApiException e) { LogUtil.w("upload onFailure: "); }@Override public void onNext(List< String> filePaths) { if (!CommonUtil.isEmpty(filePaths))//上传成功 { LogUtil.w("upload succ,filePath:" + filePaths.get(0)); DebugHelp.PrintLine("upload succ,filePath:" + filePaths.get(0)); } File dir; if (type == UPLOAD_TYPE_FUNCTION) { dir = LogCollectorUtility.getExternalDir(context, Constants.FUNCTION_DIR_NAME); } else { dir = LogCollectorUtility.getExternalDir(context, Constants.DIR_NAME); } FileToZip.recursionDeleteFile(dir); } }); }public static RequestBody parseRequestBody(File file) { return RequestBody.create(MediaType.parse("multipart/form-data"), file); }public static String parseMapKey(String key, String fileName) { return key + "\"; filename=\"" + fileName; }
/** * 上传日志 * * @return */ @Multipart @POST("v1/app/exception") Observable< ResponseBean< List< String> > > uploadLog(@PartMap Map< String, RequestBody> map);
推荐阅读
- application:didFinishLaunchingWithOptions:
- 杂项-公司(Apple)
- 实践最有效的提高Android Studio运行编译速度方案
- Android_(控件)使用ListView显示Android系统中联系人信息
- Android P Beta发布!最新版本抢先体验!
- Android Studio3.x新的依赖方式(implementationapicompileOnly)
- PHP打开文件
- PHP var_dump()函数
- PHP特殊类型