NAME
Punk::Upload - an uploaded file from a multipart form
SYNOPSIS
post '/avatar' => sub {
my ($c) = @_;
my $up = $c->req->upload('avatar') or return $c->text('no file', 400);
$up->save("/var/uploads/" . $up->filename);
$c->json({ name => $up->filename, bytes => $up->size });
};
DESCRIPTION
A file part of a multipart/form-data request. $c->req->form parses the body once: ordinary fields become parameters ($c->param), and file parts become Punk::Upload objects reachable through $c->req->upload($name) (or $c->upload($name)) and $c->req->uploads. A field uploaded more than once yields an arrayref from uploads; upload gives the first.
The bytes are held in memory in this cut - bound your request body size accordingly; a tempfile-backed mode for large uploads is a follow-on.
METHODS
filename
The client-supplied file name (do not trust it as a path).
name
The form field name.
type
The part's Content-Type (application/octet-stream if the client sent none).
size
The byte length.
content
The uploaded bytes.
save($path)
Write the bytes to $path. Croaks if it cannot open the file.
SEE ALSO
Punk, "upload" in Punk::Request.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)