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
Nested ClassesModifier and TypeClassDescriptionstatic classThe multipart/form-data specific content source.static classstatic classAn ordered list ofMultiPart.Parts that can be accessed by index or by name, or iterated over. -
Method Summary
Modifier and TypeMethodDescriptionfrom(org.eclipse.jetty.io.Content.Source content, org.eclipse.jetty.util.Attributes attributes, String contentType, MultiPartConfig config) from(org.eclipse.jetty.util.Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated.from(org.eclipse.jetty.util.Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated.get(org.eclipse.jetty.util.Attributes attributes) Returnsmultipart/form-dataparts if they have already been created.
-
Method Details
-
from
public static CompletableFuture<MultiPartFormData.Parts> from(org.eclipse.jetty.io.Content.Source content, org.eclipse.jetty.util.Attributes attributes, String contentType, MultiPartConfig config) - Parameters:
content- the source of the multipart content.attributes- the attributes where the futureParts are tracked.contentType- the value of theHttpHeader.CONTENT_TYPEheader.config- the multipart configuration.- Returns:
- the future parts
-
from
@Deprecated public static CompletableFuture<MultiPartFormData.Parts> from(org.eclipse.jetty.util.Attributes attributes, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated.Returnsmultipart/form-dataparts usingMultiPartCompliance.RFC7578. -
from
@Deprecated public static CompletableFuture<MultiPartFormData.Parts> from(org.eclipse.jetty.util.Attributes attributes, MultiPartCompliance compliance, ComplianceViolation.Listener listener, String boundary, Function<MultiPartFormData.Parser, CompletableFuture<MultiPartFormData.Parts>> parse) Deprecated.Returnsmultipart/form-dataparts using the givenMultiPartComplianceand listener.- Parameters:
attributes- the attributes where the futureParts are trackedcompliance- the compliance modelistener- the compliance violation listenerboundary- the boundary for themultipart/form-datapartsparse- the parser completable future- Returns:
- the future parts
-
get
public static CompletableFuture<MultiPartFormData.Parts> get(org.eclipse.jetty.util.Attributes attributes) Returnsmultipart/form-dataparts if they have already been created.- Parameters:
attributes- the attributes where the futureParts are tracked- Returns:
- the future parts
-
from(Content.Source, Attributes, String, MultiPartConfig).