Retrofit retrofit = new Retrofit.Builder().baseUrl("http://meipai.fangzhoukeji.com/").build(); ApiInterface apiService = retrofit.create(ApiInterface.class); RequestBody requestBody = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("file", path, RequestBody.create(MediaType.parse("video/mp4"), new File(path))) .addFormDataPart("f_file", "name") .build(); Map< String, RequestBody > params = new HashMap< >(); params.put("f_file.mp4", requestBody); Call< ResponseBody > call = apiService.upload("f_file",params); call.enqueue(new retrofit2.Callback< ResponseBody >() { @Override public void onResponse(Call< ResponseBody > call, Response< ResponseBody > response) { ToastUtil.show("onResponse"); try { String jsonString = new String(response.body().bytes()); Log.d("tag", "onResponse succ : "+jsonString); } catch (IOException e) { e.printStackTrace(); } } @Override public void onFailure(Call< ResponseBody > call, Throwable throwable) { Log.d("tag", "onFailure : "+throwable.getMessage()); ToastUtil.show("onFailure"); } }); public interface ApiInterface { @Multipart @POST("mobile/index/upvideo") Call< ResponseBody > upload(@Part("f_file") String f_file,@PartMap Map< String, RequestBody > params); } 求问:这样写哪不对吗??
回复讨论(解决方案)
@Part("f_file") String f_fil 不是这么写的,@Part() MultipartBody.Part file