求问:okhttp3+retrofit2 向服务器上传视频文件
求问:okhttp3+retrofit2 向服务器上传视频文件
发布时间:2018-02-01 来源:查字典编辑
摘要:Retrofitretrofit=newRetrofit.Builder().baseUrl("http://meipai.fangzhou...

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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类