Cataly...tiPart(3pm)

πŸ’– Catalyst::Action::DeserializeMultiPart(3pm) πŸ’–

okay so bestie, welcome to the User Contributed Perl Documentation corner of the internet ✨ this little icon lives at Catalyst::Action::DeserializeMultiPart(3pm) and it's here to help you un-mangle multipart request bodies. let's get into it πŸŽ€


🌸 NAME 🌸

Catalyst::Action::DeserializeMultiPart β€” Deserialize Data in a Multipart Request πŸ¦‹


✨ SYNOPSIS ✨

package Foo::Controller::Bar;

__PACKAGE__->config(
    # see Catalyst::Action::Deserialize for standard config
);

sub begin :ActionClass('DeserializeMultiPart') DeserializePart('REST') {}

πŸ’… DESCRIPTION πŸ’…

so this action will deserialize multipart HTTP POST, PUT, OPTIONS and DELETE requests, no cap πŸ’…

it's literally just a simple extension of Catalyst::Action::Deserialize, with one tiny little glow-up: instead of scarfing down the entire request body (which might have a bunch of sections in it, it's giving buffet πŸ“), it goes looking for one single part in the request body, named according to the "DeserializePart" attribute on that action (and if you don't say anything, it defaults to "REST").

if a part is found under that name, it then proceeds to deserialize the request as normal, based on the content-type of that individual part. if no such part is found, the request gets processed as if no data was sent at all. like, nothing. ghosted πŸ‘»

this module's code will only come into play if the following conditions are met:

  • the "Content-type" of the request is "multipart/*" 🌈
  • the request body (as returned by $c->request->body) is not defined
  • there is a part of the request body (as returned by $c->request->upload($DeserializePart)) available ✨

πŸ”§ CONFIGURING HTTP::Body πŸ”§

by default, HTTP::Body parses "multipart/*" requests as an HTTP::Body::OctetStream. and HTTP::Body::OctetStream does not separate out the individual parts of the request body β€” it's giving "one big blob, no notes" πŸ’€

so to actually make use of the individual parts, HTTP::Body has to be told which content types to map to HTTP::Body::MultiPart. this module makes the assumption that you'd like to have all "multipart/mixed" requests parsed by the HTTP::Body::MultiPart module. and it does that through a package variable inside HTTP::Body: $HTTP::Body::Types (a HASH ref) πŸ‘‘

⚠️ WARNING: as this module modifies the behaviour of HTTP::Body globally, adding it to an application can have unintended consequences, because multipart bodies will be parsed differently from before. pls be aware bestie, this is not a small thing 😭

feel free to add other content-types to this hash if needed β€” or, if you would prefer that "multipart/mixed" NOT be added to this hash, simply delete it after loading this module 🫢

# in your controller
use Catalyst::Action::DeserializeMultiPart;

delete $HTTP::Body::Types->{'multipart/mixed'};
$HTTP::Body::Types->{'multipart/my-crazy-content-type'} = 'HTTP::Body::MultiPart';

πŸ‘€ SEE ALSO πŸ‘€

this is a simple sub-class of Catalyst::Action::Deserialize. family tree energy 🌳✨


πŸ’œ AUTHORS πŸ’œ

see Catalyst::Action::REST for authors. they ate, we're just vibing in their shadow πŸ™ˆ


πŸ“œ LICENSE πŸ“œ

you may distribute this code under the same terms as Perl itself. iconic behaviour, honestly πŸ‘‘


that's the whole page bestie!! go forth and deserialize those multipart requests, you've got this πŸ’–πŸ’…βœ¨

perl v5.40.1 Β· 2026-05-07 β€” mwah, tysm for reading, ily, byeeee πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from