Annotation Interface Part
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 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. — sent verbatim (repeatable).byte []File— streamed from disk; thefileName()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
Example:
Notes:
-
Valid only on a method also annotated
@Multipart; a@Partparameter 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
-
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 forname().Allows shortened notation when only the part name is specified:
.@Part ("title" )- Returns:
- The annotation value.
- Default:
- ""
-
fileName
The filename advertised in the part'sContent-Dispositionheader.When blank, no
filenameis emitted — except for aFileargument, whose filename defaults toFile.getName().- Returns:
- The annotation value.
- Default:
- ""
-
contentType
The per-partContent-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-8for text fields, the serializer's media type for beans,application/octet-streamfor binary sources).- Returns:
- The annotation value.
- Default:
- ""
-