欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android實現(xiàn)圖片上傳功能(springMvc)

 更新時間:2017年03月02日 16:01:41   投稿:lijiao  
這篇文章主要為大家詳細介紹了android結(jié)合springMvc實現(xiàn)圖片上傳的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android圖片上傳的具體代碼,供大家參考,具體內(nèi)容如下

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, "成功");
 }

參考:android調(diào)用原生圖片裁剪后圖片尺寸縮放的解決方法

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論