.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Apache2::Upload 3pm" .TH Apache2::Upload 3pm 2024-03-02 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Apache2::Upload \- Methods for dealing with file uploads. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Apache2::Upload; \& \& $req = Apache2::Request\->new($r); \& $upload = $req\->upload("foo"); \& $size = $upload\->size; \& \& # three methods to get at the upload\*(Aqs 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>; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Apache2::Upload is a new module based on the original package included in Apache2::Request 1.X. Users requiring the upload API must now \&\f(CW\*(C`use Apache2::Upload\*(C'\fR, which adds the \f(CW\*(C`upload\*(C'\fR method to Apache2::Request. Apache2::Upload is largely backwards-compatible with the original 1.X API. See the "PORTING from 1.X" section below for a list of known issues. .PP This manpage documents the Apache2::Upload package. .SH Apache2::Upload .IX Header "Apache2::Upload" .SS name .IX Subsection "name" .Vb 1 \& $upload\->name() .Ve .PP The name of the HTML form element which generated the upload. .SS filename .IX Subsection "filename" .Vb 1 \& $upload\->filename() .Ve .PP The (client-side) filename as submitted in the HTML form. Note: some agents will submit the file's full pathname, while others may submit just the basename. .SS fh .IX Subsection "fh" .Vb 1 \& $upload\->fh() .Ve .PP Creates filehandle reference to the upload's spooled tempfile, which contains the full contents of the upload. .SS io .IX Subsection "io" .Vb 1 \& $upload\->io() .Ve .PP Creates a tied IO handle. This method is a more efficient version of \f(CW\*(C`fh\*(C'\fR, but with \f(CW\*(C`io\*(C'\fR the handle ref returned is not seekable. It is tied to an APR::Request::Brigade object, so you may use the brigade API on the tied object if you want to manipulate the IO stream (beyond simply reading from it). .PP The returned reference is actually an object which has \f(CW\*(C`read\*(C'\fR and \&\f(CW\*(C`readline\*(C'\fR methods available. However these methods are just syntactic sugar for the underlying \f(CW\*(C`READ\*(C'\fR and \f(CW\*(C`READLINE\*(C'\fR methods from APR::Request::Brigade. .PP .Vb 2 \& $io = $upload\->io; \& print while $io\->read($_); # equivalent to: tied(*$io)\->READ($_) .Ve .PP See READ and READLINE below for additional notes on their usage. .SS bb .IX Subsection "bb" .Vb 2 \& $upload\->bb() \& $upload\->bb($set) .Ve .PP Get/set the APR::Brigade which represents the upload's contents. .SS size .IX Subsection "size" .Vb 1 \& $upload\->size() .Ve .PP Returns the size of the upload in bytes. .SS info .IX Subsection "info" .Vb 2 \& $upload\->info() \& $upload\->info($set) .Ve .PP Get/set the additional header information table for the uploaded file. Returns a hash reference tied to the \fIAPR::Table\fR class. An optional \f(CW$table\fR argument can be passed to reassign the upload's internal (apr_table_t) info table to the one \&\f(CW$table\fR represents. .PP .Vb 4 \& my $info = $upload\->info; \& while (my($hdr_name, $hdr_value) = each %$info) { \& # ... \& } \& \& # fetch upload\*(Aqs Content\-Type header \& my $type = $upload\->info\->{"Content\-type"}; .Ve .SS type .IX Subsection "type" .Vb 1 \& $upload\->type() .Ve .PP Returns the MIME type of the given \fIApache2::Upload\fR object. .PP .Vb 1 \& my $type = $upload\->type; \& \& #same as \& my $content_type = $upload\->info\->{"Content\-Type"}; \& $content_type =~ s/;.*$//ms; .Ve .SS link .IX Subsection "link" .Vb 1 \& $upload\->link() .Ve .PP To avoid recopying the upload's internal tempfile brigade on a *nix\-like system, \fIlink\fR will create a hard link to it: .PP .Vb 3 \& my $upload = $req\->upload(\*(Aqfoo\*(Aq); \& $upload\->link("/path/to/newfile") or \& die sprintf "link from \*(Aq%s\*(Aq failed: $!", $upload\->tempname; .Ve .PP 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, \f(CWlink()\fR will instead copy the temporary file to the specified location. .SS slurp .IX Subsection "slurp" .Vb 1 \& $upload\->slurp($contents) .Ve .PP Reads the full contents of a file upload into the scalar argument. The return value is the length of the file. .PP .Vb 1 \& my $size = $upload\->slurp($contents); .Ve .SS tempname .IX Subsection "tempname" .Vb 1 \& $upload\->tempname() .Ve .PP Provides the name of the spool file. .PP .Vb 1 \& my $tempname = $upload\->tempname; .Ve .SH APR::Request::Brigade .IX Header "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 \f(CW\*(C`seek\*(C'\fR on handles tied to this class. Such handles have semantics similar to that of a read-only socket. .SS TIEHANDLE .IX Subsection "TIEHANDLE" .Vb 1 \& APR::Request::Brigade\->TIEHANDLE($bb) .Ve .PP Creates a copy of the bucket brigade represented by \f(CW$bb\fR, and blesses that copy into the APR::Request::Brigade class. This provides syntactic sugar for using perl's builtin \f(CW\*(C`read\*(C'\fR, \f(CW\*(C`readline\*(C'\fR, and \f(CW\*(C`<>\*(C'\fR operations on handles tied to this package: .PP .Vb 4 \& use Symbol; \& $fh = gensym; \& tie *$fh, "APR::Request:Brigade", $bb; \& print while <$fh>; .Ve .SS READ .IX Subsection "READ" .Vb 3 \& $bb\->READ($contents) \& $bb\->READ($contents, $length) \& $bb\->READ($contents, $length, $offset) .Ve .PP Reads data from the brigade \f(CW$bb\fR into \f(CW$contents\fR. When omitted \&\f(CW$length\fR defaults to \f(CW\-1\fR, which reads the first bucket into \f(CW$contents\fR. A positive \f(CW$length\fR will read in \f(CW$length\fR bytes, or the remainder of the brigade, whichever is greater. \f(CW$offset\fR represents the index in \f(CW$context\fR to read the new data. .SS READLINE .IX Subsection "READLINE" .Vb 1 \& $bb\->READLINE() .Ve .PP Returns the first line of data from the bride. Lines are terminated by linefeeds (the '\e012' character), but we may eventually use \f(CW$/\fR instead. .SH "PORTING from 1.X" .IX Header "PORTING from 1.X" .IP \(bu 4 \&\f(CW\*(C`$upload\->next()\*(C'\fR is no longer available; please use the \&\f(CW\*(C`APR::Request::Param::Table\*(C'\fR API when iterating over upload entries. .IP \(bu 4 \&\f(CWinfo($header_name)\fR is replaced by \f(CWinfo($set)\fR. .IP \(bu 4 \&\f(CWtype()\fR returns only the MIME-type portion of the Content-Type header. .SH "SEE ALSO" .IX Header "SEE ALSO" APR::Request::Param::Table, APR::Request::Error, Apache2::Request, \&\fBAPR::Table\fR\|(3) .SH COPYRIGHT .IX Header "COPYRIGHT" .Vb 6 \& 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. .Ve