.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "2019-10-02" "perl v5.28.1" "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 \s-1API\s0 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 \s-1API.\s0 See the \*(L"\s-1PORTING\s0 from 1.X\*(R" 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 \s-1HTML\s0 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 \s-1HTML\s0 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 \s-1IO\s0 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 \s-1API\s0 on the tied object if you want to manipulate the \s-1IO\s0 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 \s-1READ\s0 and \s-1READLINE\s0 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 \s-1MIME\s0 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 \s-1OS\s0 from linking the files, \f(CW\*(C`link()\*(C'\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 \s-1TIEHANDLE, READ\s0 and \s-1READLINE.\s0 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 "\s-1TIEHANDLE\s0" .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 "\s-1READ\s0" .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\*(C`\-1\*(C'\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 "\s-1READLINE\s0" .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 \s-1API\s0 when iterating over upload entries. .IP "\(bu" 4 \&\f(CW\*(C`info($header_name)\*(C'\fR is replaced by \f(CW\*(C`info($set)\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`type()\*(C'\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