NAME
PAGI::Request::Upload - Uploaded file representation
SYNOPSIS
my $upload = await $req->upload('avatar');
if ($upload && !$upload->is_empty) {
my $filename = $upload->filename;
my $size = $upload->size;
my $content = $upload->slurp;
await $upload->save_to('/path/to/save');
}
DESCRIPTION
PAGI::Request::Upload represents an uploaded file from a multipart form. Files may be stored in memory (small files) or spooled to a temporary file (large files).
CONSTRUCTOR
new
my $upload = PAGI::Request::Upload->new(
field_name => 'avatar',
filename => 'photo.jpg',
content_type => 'image/jpeg',
data => $bytes, # OR
temp_path => '/tmp/abc123', # for spooled files
size => 12345,
);
PROPERTIES
field_name
Form field name.
filename
Original filename from the upload.
basename
Filename without path components (safe for filesystem use).
content_type
MIME type of the uploaded file.
size
File size in bytes.
temp_path
Path to temporary file (if spooled to disk).
PREDICATES
is_empty
True if no data was uploaded.
is_in_memory
True if file data is stored in memory.
is_on_disk
True if file data is spooled to a temp file.
CONTENT METHODS
slurp
my $bytes = $upload->slurp;
Read entire file content into memory.
fh
my $fh = $upload->fh;
Get a filehandle for reading the upload.
ASYNC METHODS
copy_to
await $upload->copy_to('/path/to/destination');
Copy the uploaded file to a destination.
move_to
await $upload->move_to('/path/to/destination');
Move the uploaded file to a destination (more efficient for disk files).
save_to
Alias for copy_to.
CLEANUP
Temporary files are automatically deleted when the Upload object is destroyed. If you want to keep the file, use move_to or copy_to.