Retrofit上传头像
来源:互联网 发布:mac tomcat端口被占用 编辑:程序博客网 时间:2024/06/07 21:02
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build(); mRetrofit = new Retrofit.Builder().client(okHttpClient) .baseUrl(mBaseUrl) .addConverterFactory(GsonConverterFactory.create()) .build(); //先创建 service FileUploadService service = mRetrofit.create(FileUploadService.class); //构建要上传的文件 RequestBody requestFile = RequestBody.create(MediaType.parse("application/otcet-stream"), file);/*application/otcet-stream*/ MultipartBody.Part body = MultipartBody.Part.createFormData("face", file.getName(), requestFile); String descriptionString = "This is a description"; RequestBody description = RequestBody.create( MediaType.parse("multipart/form-data"), descriptionString);/*application/x-www-form-urlencoded*/ Call<ResponseBody> call = service.upload(description, body,mToken); call.enqueue(new Callback<ResponseBody>() { @Override public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { System.out.println("--------success"+response.body().toString()); showLoadingSuccess(); mCivImg.setImageBitmap(mBitmap); EventBus.getDefault().post(new FixImage(mBitmap)); } @Override public void onFailure(Call<ResponseBody> call, Throwable t) { t.printStackTrace(); showLoadingSuccess(); ToastUtil.showToast(PersonalInformationActivity.this,"上传头像失败",0); System.out.println("--------success1111111"); } });
阅读全文
0 1
- Retrofit上传头像
- Retrofit上传头像
- Retrofit上传头像
- Retrofit的POST方法上传头像
- 上传头像
- 上传头像
- 上传头像
- 上传头像
- 头像上传
- 上传头像
- 头像上传
- 头像上传
- 头像上传
- 上传头像
- 上传头像
- 头像上传
- 头像上传
- 上传头像
- python数据持久化到文件并读取:pickle的使用
- struts报错严重: Dispatcher initialization failed Unable to load configuration.
- 文本特征选择-互信息
- 数据结构之链表的实例
- log4j在spring4中的配置
- Retrofit上传头像
- Java: 对象的初始化过程
- leetcode 303. Range Sum Query
- 2 认识java虚拟机的基本结构
- StringBuffer的用法
- get请求与post提交区别的简易理解
- Caffe——Python接口学习:绘制loss和accuracy曲线
- 3 常用java虚拟机参数
- 之江学院第0届校赛决赛 A-qwb与支教(容斥+二分)