Retrofit上传多张图片

public class PublishJokeModel {
    public void publishJoke(String uid, String content, List jokeFiles)
    {
        MultipartBody.Builder builder=new MultipartBody.Builder().setType(MultipartBody.FORM);
        builder.addFormDataPart("uid",uid);
        builder.addFormDataPart("content",content);
        for (int i = 0; i new File(jokeFiles.get(i));
            RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),file);
            builder.addFormDataPart("jokeFiles",file.getName(),requestBody);
        }
          List parts=builder.build().parts();
          new RetrofitUtils.Builder().addConverterFactory()
                  .addCallAdapterFactory()
                  .builder()
                  .getService().getpublishJoke(parts)
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Observer() {
                      @Override
                      public void onSubscribe(Disposable d) {

                      }
                      @Override
                      public void onNext(ResponsBodyBean value) {
                       if(value.code.equals("0"))
                       {
                           publishJokeinterface.Success(value);

                       }
                       else if(value.code.equals("1"))
                       {
                           publishJokeinterface.Error(value.msg);
                       }
                       else
                       {
                           publishJokeinterface.onFair(value.msg);
                       }
                      }
                      @Override
                      public void onError(Throwable e) {
                      }

                      @Override
                      public void onComplete() {

                      }
                  });
                }
   private publishJokeinterface publishJokeinterface;

    public void setPublishJokeinterface(PublishJokeModel.publishJokeinterface publishJokeinterface) {
        this.publishJokeinterface = publishJokeinterface;
    }

    public interface publishJokeinterface
    {
        void Success(ResponsBodyBean bodyBean);
        void Error(String msg);
        void onFair(String msg);
    }
   }

你可能感兴趣的:(Retrofit上传多张图片)