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 <http://tools.ietf.org/html/rfc7230>, RFC 7231
18       <http://tools.ietf.org/html/rfc7231> and RFC 2388
19       <http://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 {
27           my ($multi, $single) = @_;
28           ...
29         });
30
31       Emitted when a new Mojo::Content::Single part starts.
32
33         $multi->on(part => sub {
34           my ($multi, $single) = @_;
35           return unless $single->headers->content_disposition =~ /name="([^"]+)"/;
36           say "Field: $1";
37         });
38

ATTRIBUTES

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

METHODS

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

SEE ALSO

99       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
100
101
102
103perl v5.32.0                      2020-07-28       Mojo::Content::MultiPart(3)
Impressum