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
(Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Returnsmultipart/form-data
parts usingMultiPartCompliance.RFC7578
.from
(Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Returnsmultipart/form-data
parts using the givenMultiPartCompliance
and listener.
-
Method Details
-
from
public static CompletableFuture<MultiPartFormData.Parts> from(Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Returnsmultipart/form-data
parts usingMultiPartCompliance.RFC7578
. -
from
public static CompletableFuture<MultiPartFormData.Parts> from(Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) 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
-