源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

android实现图片上传功能(springMvc)

  • 时间:2022-11-09 10:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:android实现图片上传功能(springMvc)
本文实例为大家分享了Android图片上传的具体代码,供大家参考,具体内容如下 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, "成功");
 }

参考:[url=http://www.1sucai.cn/article/107276.htm]android调用原生图片裁剪后图片尺寸缩放的解决方法[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部