Apache2::Upload(3pm)

✨ NAME ✨

Apache2::Upload β€” Methods for dealing with file uploads πŸ’–

okay so real quick, bestie, before we get into it: this is the manual page for Apache2::Upload(3pm), filed under User Contributed Perl Documentation. She's giving "upload handling, but make it official." Let's go ✨


🌸 SYNOPSIS 🌸

use Apache2::Upload;

$req = Apache2::Request->new($r);
$upload = $req->upload("foo");
$size = $upload->size;

# three methods to get at the upload's contents ... slurp, fh, io

$upload->slurp($slurp_data);

read $upload->fh, $fh_data, $size;
ok $slurp_data eq $fh_data;

my $io = $upload->io;
print while <$io>;

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically ngl, Apache2::Upload is a new module based on the original package that used to be bundled up inside Apache2::Request 1.X. If you're the kind of person who needs the upload API, the way it works now is you gotta use Apache2::Upload β€” and the minute you do, it adds the upload method to Apache2::Request. slay. πŸ’…

She's largely backwards-compatible with the original 1.X API, which is iconic of her, but not fully β€” so if you're coming from the old world, go read the "PORTING from 1.X" section down below for the list of known issues. iykyk.

And FR FR: this manpage documents the Apache2::Upload package. Periodt. πŸŽ€


πŸ‘‘ Apache2::Upload πŸ‘‘

name

  • $upload->name() β€” the name of the HTML form element that generated the upload. that's it, that's the vibe check.

filename

  • $upload->filename() β€” the (client-side) filename exactly as it was submitted in the HTML form. ⚠️ heads up though: some agents will submit the file's full pathname, while others might just submit the basename. so don't go assuming, bestie.

fh

  • $upload->fh() β€” creates a filehandle reference pointing at the upload's spooled tempfile, which holds the full contents of the upload. your little window into the whole thing 🫢

io

  • $upload->io() β€” creates a tied IO handle. this method is a more efficient version of fh, BUT β€” and this is the important part β€” with io the handle ref you get back is not seekable. πŸ™ˆ

it's tied to an APR::Request::Brigade object, so you may use the brigade API on the tied object if you wanna manipulate the IO stream (beyond simply reading from it). main character energy.

the returned reference is actually an object which has read and readline methods available. however, these methods are just syntactic sugar for the underlying READ and READLINE methods from APR::Request::Brigade. cute, right?

$io = $upload->io;
print while $io->read($_); # equivalent to: tied(*$io)->READ($_)

See READ and READLINE below for additional notes on their usage. πŸ“

bb

  • $upload->bb()
  • $upload->bb($set)

Get/set the APR::Brigade which represents the upload's contents. getter and setter, one little method, doing the absolute most πŸ’…

size

  • $upload->size() β€” returns the size of the upload in bytes. that's the whole thing. no cap.

info

  • $upload->info()
  • $upload->info($set)

Get/set the additional header information table for the uploaded file. Returns a hash reference tied to the APR::Table class. An optional $table argument can be passed to reassign the upload's internal (apr_table_t) info table to the one $table represents.

my $info = $upload->info;
while (my($hdr_name, $hdr_value) = each %$info) {
    # ...
}

# fetch upload's Content-Type header
my $type = $upload->info->{"Content-type"};

type

  • $upload->type() β€” returns the MIME type of the given Apache2::Upload object. ✨
my $type = $upload->type;

#same as
my $content_type = $upload->info->{"Content-Type"};
$content_type =~ s/;.*$//ms;
  • $upload->link() β€” to avoid recopying the upload's internal tempfile brigade on a *nix-like system, link will create a hard link to it:
my $upload = $req->upload('foo');
$upload->link("/path/to/newfile") or
    die sprintf "link from '%s' failed: $!", $upload->tempname;

typically the new name must lie on the same device and partition as the brigade's tempfile. if this or any other reason prevents the OS from linking the files, link() will instead copy the temporary file to the specified location. so either way you're getting your file, she's just trying the fast route first πŸ¦‹

slurp

  • $upload->slurp($contents) β€” reads the full contents of a file upload into the scalar argument. the return value is the length of the file. πŸ“
my $size = $upload->slurp($contents);

tempname

  • $upload->tempname() β€” provides the name of the spool file. it's giving "where did you stash it," and now you know. πŸ‘‘
my $tempname = $upload->tempname;

🧚 APR::Request::Brigade 🧚

This class is derived from APR::Brigade, providing additional methods for TIEHANDLE, READ and READLINE.

⚠️ To be memory efficient, these methods delete buckets from the brigade as soon as their data is actually read, so you cannot "seek" on handles tied to this class. Such handles have semantics similar to that of a read-only socket. don't try it, bestie, it will not go well for you πŸ’€

TIEHANDLE

  • APR::Request::Brigade->TIEHANDLE($bb) β€” creates a copy of the bucket brigade represented by $bb, and blesses that copy into the APR::Request::Brigade class. This provides syntactic sugar for using perl's builtin read, readline, and <> operations on handles tied to this package:
use Symbol;
$fh = gensym;
tie *$fh, "APR::Request:Brigade", $bb;
print while <$fh>;

READ

  • $bb->READ($contents)
  • $bb->READ($contents, $length)
  • $bb->READ($contents, $length, $offset)

Reads data from the brigade $bb into $contents. When omitted, $length defaults to -1, which reads the first bucket into $contents. A positive $length will read in $length bytes, or the remainder of the brigade, whichever is greater. $offset represents the index in $context to read the new data.

READLINE

  • $bb->READLINE() β€” returns the first line of data from the bride. (yes, "bride" β€” that's what it says in the source, typo and all, we love her 😭) Lines are terminated by linefeeds (the '\012' character), but we may eventually use $/ instead.

🌈 PORTING from 1.X 🌈

ooh okay bestie, here's the glow-up checklist β€” things that changed from 1.X, so you don't get caught out:

  • $upload->next() is no longer available; please use the APR::Request::Param::Table API when iterating over upload entries.
  • info($header_name) is replaced by info($set).
  • type() returns only the MIME-type portion of the Content-Type header.

πŸ’œ SEE ALSO πŸ’œ

APR::Request::Param::Table, APR::Request::Error, Apache2::Request, APR::Table(3)

go read those too, they're all part of the same little family 🫢


Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

aaaaand that's the whole thing, bestie πŸ’– this page is perl v5.42.3, dated 2026-08-21, and it's the manpage for Apache2::Upload(3pm). go forth and upload responsibly. mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from