public void uploadImage(String interfaceUrl,String filePath,String idCardNo) {
Logger.d(“interfaceUrl:”+interfaceUrl);
OkHttpClient mOkHttpClient = new OkHttpClient();
File file = new File(filePath);
if (file.exists()){
MultipartBody.Builder builder = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(“aac002”,idCardNo)
.addFormDataPart(“file”, file.getName(),
RequestBody.create(MediaType.parse(“image/*”), file));

        RequestBody requestBody = builder.build();        Request request = new Request.Builder()                .url(interfaceUrl)                .post(requestBody)                .build();        Call call = mOkHttpClient.newCall(request);        call.enqueue(new Callback() {            @Override            public void onFailure(Call call, IOException e) {                Log.e(TAG, "onFailure: "+e );            }            @Override            public void onResponse(Call call, Response response) throws IOException {                ResponseBody body = response.body();                String output = body.string();                Log.e(TAG, "成功:"+output);            }        });    }else{        Logger.e(TAG, "文件为空");    }}

更多相关文章

  1. Android日志服务 记录日志
  2. AndroidManifest.xml文件详解(uses-configuration)
  3. android studio Error:Unable to start the daemon process
  4. android studio Error:Unable to start the daemon process
  5. [置顶] android调用系统相机拍照并保存在本地
  6. Android(安卓)AES 文件加密解密
  7. Android(安卓)Studio设置gradle代理
  8. Android(安卓)文件打开方式
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android之Handler详解(二)
  2. Android进阶之android应用的SDK版本之间
  3. 【android原生应用】之闹钟应用搭起篇
  4. [置顶] 手机信息备份和恢复系统
  5. Android 面试题之编程
  6. Android(安卓)性能优化之内存检测、卡顿
  7. android网络编程——http post
  8. Mono for Android, C# for Android,Monodr
  9. Banner的简单实用
  10. ARouter的基本使用