Annotation Interface Part


REST request multipart/form-data part annotation.

Identifies a method parameter on a Remote-proxy method (which must also be marked @Multipart) as a single part of a multipart/form-data request body — the Retrofit @Part pattern. The engine adapts each @Part parameter into the streaming MultipartBody.

Accepted part-source types

The bound argument type determines how the part body is produced:

  • CharSequence/String (and other scalars such as numbers/booleans) — sent as a text field.
  • byte[] — sent verbatim (repeatable).
  • File — streamed from disk; the fileName() defaults to the file's name.
  • InputStream — streamed (one-shot; makes the request body non-repeatable).
  • Reader — streamed as UTF-8 (one-shot; not drained during request building).
  • An HttpBody — used directly.
  • Any other object (a bean) — serialized with the client's default serializer (e.g. JSON).

A null argument contributes no part.

Example:

@RemotePost("/upload") @Multipart String upload( @Part("title") String title, @Part(name="attachment", fileName="report.pdf", contentType="application/pdf") byte[] data);

Notes:
  • Valid only on a method also annotated @Multipart; a @Part parameter on a non-multipart method is rejected at proxy-build time.
  • Honored by the next-generation engine (RestClient.remote(...)) only; the classic engine currently ignores this annotation.
See Also:
Since:
9.2.1
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The per-part Content-Type (e.g.
    The filename advertised in the part's Content-Disposition header.
    The part (form-field) name.
    A synonym for name().
  • Element Details

    • name

      The part (form-field) name.

      When blank, falls back to value(), then to the reflected parameter name (requires the -parameters compiler flag).

      Returns:
      The annotation value.
      Default:
      ""
    • value

      A synonym for name().

      Allows shortened notation when only the part name is specified: @Part("title").

      Returns:
      The annotation value.
      Default:
      ""
    • fileName

      The filename advertised in the part's Content-Disposition header.

      When blank, no filename is emitted — except for a File argument, whose filename defaults to File.getName().

      Returns:
      The annotation value.
      Default:
      ""
    • contentType

      The per-part Content-Type (e.g. "application/pdf", "application/json").

      When blank, a sensible default is used based on the argument type (e.g. text/plain; charset=UTF-8 for text fields, the serializer's media type for beans, application/octet-stream for binary sources).

      Returns:
      The annotation value.
      Default:
      ""