Package org.eclipse.jetty.http
Class MultiPartFormData
java.lang.Object
org.eclipse.jetty.http.MultiPartFormData
A CompletableFuture
that is completed when a multipart/form-data content
has been parsed asynchronously from a Content.Source
.
Once the parsing of the multipart/form-data content completes successfully,
objects of this class are completed with a MultiPartFormData.Parts
object.
Objects of this class may be configured to save multipart files in a configurable directory, and configure the max size of such files, etc.
Typical usage:
// Some headers that include Content-Type.
HttpFields headers = ...;
String boundary = MultiPart.extractBoundary(headers.get(HttpHeader.CONTENT_TYPE));
// Some multipart/form-data content.
Content.Source content = ...;
// Create and configure MultiPartFormData.
MultiPartFormData.Parser formData = new MultiPartFormData.Parser(boundary);
// Where to store the files.
formData.setFilesDirectory(Path.of("/tmp"));
// Max 1 MiB files.
formData.setMaxFileSize(1024 * 1024);
// Parse the content.
formData.parse(content)
// When complete, use the parts.
.thenAccept(parts -> ...);
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The multipart/form-data specific content source.static class
static class
An ordered list ofMultiPart.Part
s that can be accessed by index or by name, or iterated over. -
Method Summary
Modifier and TypeMethodDescriptionfrom
(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config) Deprecated, for removal: This API element is subject to removal in a future version.from
(Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated, for removal: This API element is subject to removal in a future version.from
(Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated, for removal: This API element is subject to removal in a future version.get
(Attributes attributes) Deprecated, for removal: This API element is subject to removal in a future version.static MultiPartFormData.Parts
getParts
(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config) Getmultipart/form-data
MultiPartFormData.Parts
from aContent.Source
, caching the results in anAttributes
.static MultiPartFormData.Parts
getParts
(Attributes attributes) Getmultipart/form-data
MultiPartFormData.Parts
from anAttributes
, typically cached there by calls togetParts(Content.Source, Attributes, String, MultiPartConfig)
oronParts(Content.Source, Attributes, String, MultiPartConfig, Promise.Invocable)
static void
onParts
(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config, Promise.Invocable<MultiPartFormData.Parts> promise) Asynchronously getmultipart/form-data
MultiPartFormData.Parts
from aContent.Source
, caching the results in anAttributes
.
-
Method Details
-
getParts
Getmultipart/form-data
MultiPartFormData.Parts
from anAttributes
, typically cached there by calls togetParts(Content.Source, Attributes, String, MultiPartConfig)
oronParts(Content.Source, Attributes, String, MultiPartConfig, Promise.Invocable)
- Parameters:
attributes
- the attributes where the futureParts are cahced- Returns:
- the parts or null
-
getParts
public static MultiPartFormData.Parts getParts(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config) Getmultipart/form-data
MultiPartFormData.Parts
from aContent.Source
, caching the results in anAttributes
. If not already available, theParts
are read and parsed, blocking if necessary.Calls to
onParts
andgetParts
methods are idempotent, and can be called multiple times, with subsequent calls returning the results of the first call.- Parameters:
content
- the source of the multipart content.attributes
- the attributes where the Parts are cached.contentType
- the value of theHttpHeader.CONTENT_TYPE
header.config
- the multipart configuration.- Returns:
- the parts
-
onParts
public static void onParts(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config, Promise.Invocable<MultiPartFormData.Parts> promise) Asynchronously getmultipart/form-data
MultiPartFormData.Parts
from aContent.Source
, caching the results in anAttributes
. If not already available, theParts
are read and parsed.Calls to
onParts
andgetParts
methods are idempotent, and can be called multiple times, with subsequent calls returning the results of the first call.- Parameters:
content
- the source of the multipart content.attributes
- the attributes where the futureParts are tracked.contentType
- the value of theHttpHeader.CONTENT_TYPE
header.config
- the multipart configuration.promise
- The action to take when theMultiPartFormData.Parts
are available.
-
from
@Deprecated(forRemoval=true, since="12.0.15") public static CompletableFuture<MultiPartFormData.Parts> from(Content.Source content, Attributes attributes, String contentType, MultiPartConfig config) Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
content
- the source of the multipart content.attributes
- the attributes where the futureParts are tracked.contentType
- the value of theHttpHeader.CONTENT_TYPE
header.config
- the multipart configuration.- Returns:
- the future parts
-
from
@Deprecated(forRemoval=true, since="12.0.15") public static CompletableFuture<MultiPartFormData.Parts> from(Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated, for removal: This API element is subject to removal in a future version.Returnsmultipart/form-data
parts usingMultiPartCompliance.RFC7578
. -
from
@Deprecated(forRemoval=true, since="12.0.15") public static CompletableFuture<MultiPartFormData.Parts> from(Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated, for removal: This API element is subject to removal in a future version.Returnsmultipart/form-data
parts using the givenMultiPartCompliance
and listener.- Parameters:
attributes
- the attributes where the futureParts are trackedcompliance
- the compliance modelistener
- the compliance violation listenerboundary
- the boundary for themultipart/form-data
partsparse
- the parser completable future- Returns:
- the future parts
-
get
@Deprecated(forRemoval=true, since="12.0.15") public static CompletableFuture<MultiPartFormData.Parts> get(Attributes attributes) Deprecated, for removal: This API element is subject to removal in a future version.Returnsmultipart/form-data
parts if they have already been created.- Parameters:
attributes
- the attributes where the futureParts are tracked- Returns:
- the future parts
-
getParts(Content.Source, Attributes, String, MultiPartConfig)
and/oronParts(Content.Source, Attributes, String, MultiPartConfig, Promise.Invocable)