1Mojo::Content::MultiParUts(e3r)Contributed Perl DocumentMaotjioo:n:Content::MultiPart(3)
2
3
4

NAME

6       Mojo::Content::MultiPart - HTTP multipart content
7

SYNOPSIS

9         use Mojo::Content::MultiPart;
10
11         my $multi = Mojo::Content::MultiPart->new;
12         $multi->parse('Content-Type: multipart/mixed; boundary=---foobar');
13         my $single = $multi->parts->[4];
14

DESCRIPTION

16       Mojo::Content::MultiPart is a container for HTTP multipart content,
17       based on RFC 7230 <https://tools.ietf.org/html/rfc7230>, RFC 7231
18       <https://tools.ietf.org/html/rfc7231> and RFC 2388
19       <https://tools.ietf.org/html/rfc2388>.
20

EVENTS

22       Mojo::Content::MultiPart inherits all events from Mojo::Content and can
23       emit the following new ones.
24
25   part
26         $multi->on(part => sub ($multi, $single) {...});
27
28       Emitted when a new Mojo::Content::Single part starts.
29
30         $multi->on(part => sub ($multi, $single) {
31           return unless $single->headers->content_disposition =~ /name="([^"]+)"/;
32           say "Field: $1";
33         });
34

ATTRIBUTES

36       Mojo::Content::MultiPart inherits all attributes from Mojo::Content and
37       implements the following new ones.
38
39   parts
40         my $parts = $multi->parts;
41         $multi    = $multi->parts([Mojo::Content::Single->new]);
42
43       Content parts embedded in this multipart content, usually
44       Mojo::Content::Single objects.
45

METHODS

47       Mojo::Content::MultiPart inherits all methods from Mojo::Content and
48       implements the following new ones.
49
50   body_contains
51         my $bool = $multi->body_contains('foobarbaz');
52
53       Check if content parts contain a specific string.
54
55   body_size
56         my $size = $multi->body_size;
57
58       Content size in bytes.
59
60   build_boundary
61         my $boundary = $multi->build_boundary;
62
63       Generate a suitable boundary for content and add it to "Content-Type"
64       header.
65
66   clone
67         my $clone = $multi->clone;
68
69       Return a new Mojo::Content::MultiPart object cloned from this content
70       if possible, otherwise return "undef".
71
72   get_body_chunk
73         my $bytes = $multi->get_body_chunk(0);
74
75       Get a chunk of content starting from a specific position. Note that it
76       might not be possible to get the same chunk twice if content was
77       generated dynamically.
78
79   is_multipart
80         my $bool = $multi->is_multipart;
81
82       True, this is a Mojo::Content::MultiPart object.
83
84   new
85         my $multi = Mojo::Content::MultiPart->new;
86         my $multi
87           = Mojo::Content::MultiPart->new(parts => [Mojo::Content::Single->new]);
88         my $multi
89           = Mojo::Content::MultiPart->new({parts => [Mojo::Content::Single->new]});
90
91       Construct a new Mojo::Content::MultiPart object and subscribe to event
92       "read" in Mojo::Content with default content parser.
93

SEE ALSO

95       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
96
97
98
99perl v5.34.0                      2022-01-21       Mojo::Content::MultiPart(3)
Impressum