Java Code Examples for retrofit2.http.Part

The following are top voted examples for showing how to use retrofit2.http.Part. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void bodyInNonBodyRequest() {
  class Example {
    @Multipart //
    @PUT("/") //
    Call<ResponseBody> method(@Part("one") String o1, @Body String o2) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Body parameters cannot be used with form or multi-part encoding. (parameter #2)\n    for method Example.method");
  }
}
 
Example 2
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartRequiresName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part RequestBody part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 3
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartOkHttpPartForbidsName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("name") MultipartBody.Part part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 4
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartArrayOkHttpPart() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") MultipartBody.Part[] part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 5
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartPartMapRejectsOkHttpPartValues() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@PartMap Map<String, MultipartBody.Part> parts) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@PartMap values cannot be MultipartBody.Part. Use @Part List<Part> or a different value type instead. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 6
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void bodyInNonBodyRequest() {
  class Example {
    @Multipart //
    @PUT("/") //
    Call<ResponseBody> method(@Part("one") String o1, @Body String o2) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Body parameters cannot be used with form or multi-part encoding. (parameter #2)\n    for method Example.method");
  }
}
 
Example 7
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartRequiresName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part RequestBody part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 8
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartIterableRequiresName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part List<RequestBody> part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 9
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartOkHttpPartForbidsName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("name") MultipartBody.Part part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 10
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartIterableOkHttpPart() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") List<MultipartBody.Part> part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 11
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartArrayOkHttpPart() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") MultipartBody.Part[] part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 12
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartPartMapRejectsOkHttpPartValues() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@PartMap Map<String, MultipartBody.Part> parts) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@PartMap values cannot be MultipartBody.Part. Use @Part List<Part> or a different value type instead. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
Example 13
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartNullRemovesPart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String ping, @Part("fizz") String fizz) {
      return null;
    }
  }
  Request request = buildRequest(Example.class, "pong", null);
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong\r\n--");
}
 
Example 14
Project: GitHub   File: RequestBuilderTest.java   View source code 6 votes vote down vote up
@Test public void multipartPartsShouldBeInOrder() throws IOException {
  class Example {
    @Multipart
    @POST("/foo")
    Call<ResponseBody> get(@Part("first") String data, @Part("second") String dataTwo, @Part("third") String dataThree) {
      return null;
    }
  }
  Request request = buildRequest(Example.class, "firstParam", "secondParam", "thirdParam");
  MultipartBody body = (MultipartBody) request.body();

  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String readBody = buffer.readUtf8();

  assertThat(readBody.indexOf("firstParam")).isLessThan(readBody.indexOf("secondParam"));
  assertThat(readBody.indexOf("secondParam")).isLessThan(readBody.indexOf("thirdParam"));
}
 
Example 15
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void implicitMultipartForbidden() {
  class Example {
    @POST("/") //
    Call<ResponseBody> method(@Part("a") int a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters can only be used with multipart encoding. (parameter #1)\n    for method Example.method");
  }
}
 
Example 16
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void simpleMultipart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String ping, @Part("kit") RequestBody kit) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, "pong", RequestBody.create(
      MediaType.parse("text/plain"), "kat"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"")
      .contains("\r\nkat\r\n--");
}
 
Example 17
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartArray() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String[] ping) {
      return null;
    }
  }

  Request request =
      buildRequest(Example.class, new Object[] { new String[] { "pong1", "pong2" } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
Example 18
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartOkHttpIterablePart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part List<MultipartBody.Part> part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request = buildRequest(Example.class, Arrays.asList(part1, part2));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
Example 19
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartOkHttpArrayPart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part MultipartBody.Part[] part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request =
      buildRequest(Example.class, new Object[] { new MultipartBody.Part[] { part1, part2 } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
Example 20
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartIterable() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") List<String> ping) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, Arrays.asList("pong1", "pong2"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
Example 21
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartWithEncoding() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part(value = "ping", encoding = "8-bit") String ping,
        @Part(value = "kit", encoding = "7-bit") RequestBody kit) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, "pong", RequestBody.create(
      MediaType.parse("text/plain"), "kat"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("Content-Transfer-Encoding: 8-bit")
      .contains("\r\npong\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"")
      .contains("Content-Transfer-Encoding: 7-bit")
      .contains("\r\nkat\r\n--");
}
 
Example 22
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartPartOptional() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") RequestBody ping) {
      return null;
    }
  }
  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalStateException e) {
    assertThat(e.getMessage()).isEqualTo("Multipart body must have at least one part.");
  }
}
 
Example 23
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void simpleMultipart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String ping, @Part("kit") RequestBody kit) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, "pong", RequestBody.create(
      MediaType.parse("text/plain"), "kat"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"")
      .contains("\r\nkat\r\n--");
}
 
Example 24
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartArray() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String[] ping) {
      return null;
    }
  }

  Request request =
      buildRequest(Example.class, new Object[] { new String[] { "pong1", "pong2" } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
Example 25
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartOkHttpIterablePart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part List<MultipartBody.Part> part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request = buildRequest(Example.class, Arrays.asList(part1, part2));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
Example 26
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartOkHttpArrayPart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part MultipartBody.Part[] part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request =
      buildRequest(Example.class, new Object[] { new MultipartBody.Part[] { part1, part2 } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
Example 27
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartIterable() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") List<String> ping) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, Arrays.asList("pong1", "pong2"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
Example 28
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartWithEncoding() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part(value = "ping", encoding = "8-bit") String ping,
        @Part(value = "kit", encoding = "7-bit") RequestBody kit) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, "pong", RequestBody.create(
      MediaType.parse("text/plain"), "kat"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("Content-Transfer-Encoding: 8-bit")
      .contains("\r\npong\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"")
      .contains("Content-Transfer-Encoding: 7-bit")
      .contains("\r\nkat\r\n--");
}
 
Example 29
Project: GitHub   File: RequestBuilderTest.java   View source code 5 votes vote down vote up
@Test public void multipartPartOptional() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") RequestBody ping) {
      return null;
    }
  }
  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalStateException e) {
    assertThat(e.getMessage()).isEqualTo("Multipart body must have at least one part.");
  }
}
 
Example 30
Project: EvolvingNetLib   File: CCNetApiService.java   View source code 5 votes vote down vote up
/**
 * 上传文件
 * @param url
 * @param headerMap
 * @param paramPartList
 * @return
 */
@Multipart
@POST
Call<ResponseBody> executeUpload(
        @Url String url,
        @HeaderMap Map<String, String> headerMap,
        @Part() List<MultipartBody.Part> paramPartList
);
 
Example 31
Project: Renrentou   File: RegService.java   View source code 5 votes vote down vote up
@POST("user/regist/person")
@Multipart
Flowable<ResponseDto<User>> regPerson(
        @PartMap Map<String, RequestBody> param,
        @Part MultipartBody.Part front,
        @Part MultipartBody.Part back
);
 
Example 32
Project: Renrentou   File: AdService.java   View source code 5 votes vote down vote up
@POST("ad/new")
@Multipart
Flowable<ResponseDto<User>> add(
        @PartMap Map<String, RequestBody> param,
        @Part MultipartBody.Part adFile,
        @Part MultipartBody.Part coverFile
);
 
Example 33
Project: Bigbang   File: OcrService.java   View source code 5 votes vote down vote up
@Headers({
        "User-Agent: Mozilla/5.0",
        "accept-language:zh-CN,zh;q=0.8"
})
@Multipart// 参数的类型都应该是RequestBody,不然上传的图片的时候会报JSON must start with an array or an object错误
@POST("parse/image/")
Observable<OcrItem> uploadImage(@Part("apikey")String key , @Part("fileName") String description,
                         @Part("file\"; filename=\"image.png\"") RequestBody imgs);
 
Example 34
Project: retrofit-rxjava-request-with-progress   File: Api.java   View source code 5 votes vote down vote up
@Multipart
@POST("pictureup/uploadshitu")
Observable<ProgressBean<String>> uploadPic(
        @Part("pos") String pos,
        @Part("uptype") String uptype,
        @Part("fm") String index,
        @Part("image\"; filename=\"xxx.jpg") File image
);
 
Example 35
Project: Plamber-Android   File: PlamberAPI.java   View source code 5 votes vote down vote up
@Multipart
@POST("api/v1/upload-book/")
Call<Upload.UploadBookRespond> uploadFile(@Part("user_token") RequestBody userToken,
                                          @Part("book_name") RequestBody bookName,
                                          @Part("author") RequestBody authorName,
                                          @Part("category") RequestBody categoryName,
                                          @Part("about") RequestBody aboutBook,
                                          @Part("language") RequestBody languageBook,
                                          @Part("private_book") boolean private_book,
                                          @Part MultipartBody.Part file,
                                          @Part MultipartBody.Part cover);
 
Example 36
Project: richeditor   File: UploadHelper.java   View source code 4 votes vote down vote up
public static MultipartBody.Part generateMultiPart(String parName,File file,RequestBodyWrapper uploadFileRequestBody){
    return MultipartBody.Part.createFormData(parName, file.getName(),uploadFileRequestBody);
}
 
Example 37
Project: ForeverLibrary   File: API.java   View source code 4 votes vote down vote up
@Multipart
@POST("api/upload/android")
Observable<BasicResponse<List<UploadModel>>> uploadFile(@Part("pic\"; filename=\"image1.png") RequestBody file);
 
Example 38
Project: richeditor   File: UploadHelper.java   View source code 4 votes vote down vote up
@Multipart
@POST
Observable<ResponseBody> uploadFile(@Url String url, @Part MultipartBody.Part file);
 
Example 39
Project: android-retrofit-image-upload   File: RetrofitInterface.java   View source code 4 votes vote down vote up
@Multipart
@POST("/images/upload")
Call<Response> uploadImage(@Part MultipartBody.Part image);
 
Example 40
Project: Bing   File: RestService.java   View source code 4 votes vote down vote up
@Multipart
@POST
Call<String> upload(@Url String url, @Part MultipartBody.Part file);