SoFunction
Updated on 2025-03-11

Android implements image upload function (springMvc)

This article shares the specific code for Android image upload for your reference. The specific content is as follows

Android side:

String fileName = ().toString();
 RequestBody description =
  (
   , fileName);

 File fileImage = new File(saveFileName);
 RequestBody requestBody1 =
  (("multipart/form-data"), fileImage);
  body =
  ("bannerImage", (), requestBody1);


 ().addLive(description, body)
 .enqueue(new <ResponseInfo>() {
  @Override
  public void onResponse(<ResponseInfo> call, <ResponseInfo> response) {
  "Processing successfully"
  }

  @Override
  public void onFailure(<ResponseInfo> call, Throwable t) {
  "Processing failed"
  }
 });

@Multipart
 @POST("add/live")
 Call<ResponseInfo> addLive(
  @Part("fileName")RequestBody fileName,//Other fields  @Part  bannerImage);//picture

Server side:

@RequestMapping(value = "/add/live", method = )
 @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);
  (file, ());

 } catch (Exception e) {
  ();
 }
 return new ResponseInfo(, "success");
 }

refer to:Solution to the size scaling of the image after Android calls native image cropping

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.