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.
42 =head2 $upload->copy_to
44 Copies the temporary file using L<File::Copy>. Returns true for success,
47 $upload->copy_to('/path/to/target');
53 return File::Copy::copy( $self->tempname, @_ );
58 Opens a temporary file (see tempname below) and returns an L<IO::File> handle.
65 my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
67 unless ( defined $fh ) {
69 my $filename = $self->tempname;
71 Catalyst::Exception->throw(
72 message => qq/Can't open '$filename': '$!'/ );
78 =head2 $upload->filename
80 Returns the client-supplied filename.
82 =head2 $upload->headers
84 Returns an L<HTTP::Headers> object for the request.
86 =head2 $upload->link_to
88 Creates a hard link to the temporary file. Returns true for success,
91 $upload->link_to('/path/to/target');
96 my ( $self, $target ) = @_;
97 return CORE::link( $self->tempname, $target );
102 Returns the size of the uploaded file in bytes.
104 =head2 $upload->slurp
106 Returns a scalar containing the contents of the temporary file.
111 my ( $self, $layer ) = @_;
118 my $handle = $self->fh;
120 binmode( $handle, $layer );
122 while ( $handle->sysread( my $buffer, 8192 ) ) {
129 =head2 $upload->tempname
131 Returns the path to the temporary file.
135 Returns the client-supplied Content-Type.
139 Sebastian Riedel, C<sri@cpan.org>
141 Christian Hansen, C<ch@ngmedia.com>
145 This program is free software, you can redistribute it and/or modify
146 it under the same terms as Perl itself.