1 package Catalyst::Request::Upload;
4 use base 'Class::Accessor::Fast';
6 use Catalyst::Exception;
10 __PACKAGE__->mk_accessors(qw/filename headers size tempname type/);
12 sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
16 Catalyst::Request::Upload - handles file upload requests
34 This class provides accessors and methods to handle client upload requests.
44 =item $upload->copy_to
46 Copies the temporary file using L<File::Copy>. Returns true for success,
49 $upload->copy_to('/path/to/target');
55 return File::Copy::copy( $self->tempname, @_ );
60 Opens a temporary file (see tempname below) and returns an L<IO::File> handle.
67 my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
69 unless ( defined $fh ) {
71 my $filename = $self->tempname;
73 Catalyst::Exception->throw(
74 message => qq/Can't open '$filename': '$!'/ );
80 =item $upload->filename
82 Returns the client-supplied filename.
84 =item $upload->headers
86 Returns an L<HTTP::Headers> object for the request.
88 =item $upload->link_to
90 Creates a hard link to the temporary file. Returns true for success,
93 $upload->link_to('/path/to/target');
98 my ( $self, $target ) = @_;
99 return CORE::link( $self->tempname, $target );
104 Returns the size of the uploaded file in bytes.
108 Returns a scalar containing the contents of the temporary file.
113 my ( $self, $layer ) = @_;
120 my $handle = $self->fh;
122 binmode( $handle, $layer );
124 while ( $handle->sysread( my $buffer, 8192 ) ) {
131 =item $upload->tempname
133 Returns the path to the temporary file.
137 Returns the client-supplied Content-Type.
143 Sebastian Riedel, C<sri@cpan.org>
145 Christian Hansen, C<ch@ngmedia.com>
149 This program is free software, you can redistribute it and/or modify
150 it under the same terms as Perl itself.