本篇文章为大家展示了如何android在中使用springMvc实现图片上传功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

相城ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
具体内容如下
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() {
@Override
public void onResponse(retrofit2.Call call, retrofit2.Response response) {
"处理成功"
}
@Override
public void onFailure(retrofit2.Call call, Throwable t) {
"处理失败"
}
}); @Multipart
@POST("add/live")
Call 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, "成功");
}上述内容就是如何android在中使用springMvc实现图片上传功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。