OkHttp+Retrofit实现多图上传

ApiService

@POST(Api.uploadSickCirclePicture)//URI地址
    @Multipart
    Observable uploadSickCirclePicture(@Query("sickCircleId") String sickCircleId,
                                                     @Part List files);

代码

                      List files=new ArrayList<>();
                  //本地图片路径localMedia.get(i).getPath();
                        String path = localMedia.get(i).getPath();
                        File file = new File(path);
         
                        //上传
                        RequestBody requestBody = MultipartBody.create(MediaType.parse("multipart/form-data"), file);
                        MultipartBody.Part image = MultipartBody.Part.createFormData("picture", file.getName(), requestBody);
                        files.add(image);

        //请求接口
         presenter.requestUploadSickCirclePicture(id, files);
                   

你可能感兴趣的:(OkHttp+Retrofit实现多图上传)