手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >求问:okhttp3+retrofit2 向服务器上传视频文件
求问:okhttp3+retrofit2 向服务器上传视频文件
摘要: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

【求问:okhttp3+retrofit2 向服务器上传视频文件】相关文章:

android平台获取手机所在位置经纬度

android计算pad或手机的分辨率/像素/密度/屏幕尺寸/DPI值的方法

android Watchdog 实现剖析

Android HttpClient GET或者POST请求基本使用方法

如何配置安卓模拟器 dex文件不被优化成odex

Android 在其他线程中更新UI线程的解决方法

Android SharedPreferences的使用分析

android中Invalidate和postInvalidate的更新view区别

Android应用中调用系统软件打开各种各样的文件

更新android SDK 失败的解决方法

精品推荐
分类导航