android图片上传springMvc
来源:互联网 发布:android安装 mysql 编辑:程序博客网 时间:2024/05/16 17:13
android端:
String fileName = tvFilename.getText().toString(); RequestBody description = RequestBody.create( okhttp3.MultipartBody.FORM, fileName); File fileImage = new File(saveFileName); RequestBody requestBody1 = RequestBody.create(MediaType.parse("multipart/form-data"), fileImage); MultipartBody.Part body = MultipartBody.Part.createFormData("bannerImage", fileImage.getName(), requestBody1); RestClient.api().addLive(description, body) .enqueue(new retrofit2.Callback<ResponseInfo>() { @Override public void onResponse(retrofit2.Call<ResponseInfo> call, retrofit2.Response<ResponseInfo> response) { "处理成功" } @Override public void onFailure(retrofit2.Call<ResponseInfo> call, Throwable t) { "处理失败" } });
@Multipart @POST("add/live") Call<ResponseInfo> addLive( @Part("fileName")RequestBody fileName,//其他字段 @Part MultipartBody.Part bannerImage);//图片
服务器端:
@RequestMapping(value = "/add/live", method = RequestMethod.POST) @ResponseBody public ResponseInfo addLive( @RequestParam(value = "fileName") String fileName, @RequestParam(value = "bannerImage") MultipartFile bannerImage )throws Exception { String logoPath = "/logo/score/"; try { File file = new File(imagePath + logoPath); FileUtils.writeByteArrayToFile(file, bannerImage.getBytes()); } catch (Exception e) { e.printStackTrace(); } return new ResponseInfo(T1TConstants.SUCCESS, "成功"); }
参考:http://blog.csdn.net/bluejww/article/details/52856213
https://medium.com/@adinugroho/upload-image-from-android-app-using-retrofit-2-ae6f922b184c#.pghubpxxk
0 0
- android图片上传springMvc
- Android Base64上传图片到 SpringMVC服务器
- Android Base64上传图片到 SpringMVC服务器
- SpringMVC 上传图片
- SpringMvc上传图片
- springMVC多图片上传
- SpringMVC图片上传
- springmvc上传多图片
- springmvc多图片上传
- springmvc上传图片实例
- springmvc上传图片
- springmvc上传图片文件
- Springmvc 上传图片
- springmvc上传图片
- SpringMvc图片上传
- SpringMVC图片上传
- springmvc上传图片
- springmvc图片上传问题
- angular1 state路由传参/foreach循环
- 乐观锁,悲观锁,事务
- 使用CM 5.3.x安装集群监控服务CMS.mp4
- 遍历文件夹输出版本信息
- ECMAScript6入门简述&索引篇(摘自阮一峰的《ECMAScript 6 入门》)
- android图片上传springMvc
- 自定义手机号码分割样式"188 8888 8888"的EditText
- 实力打脸!2017大量热门行业等着程序员,谁还敢黑程序员?
- 重写FragmentTabHost,避免导航栏切换过程中再次创建内容页面Fragment
- SpringMVC拦截器
- “空”的艺术-当数据为空时显示什么
- mysql5.7.1.16出现[Err] 1146
- TensorFlow学习(一)入门
- jsp中<jsp:forward page=""/>和response.sendRedirect("")两种跳转的区别