-C<Apache::Request> and its C<Apache::Upload> objects. If we're planning to use
-C<CGI::Maypole> instead, or want to write our application in a generic way so
-that it'll work regardless of front-end, then we need to replace the C<upload>
-call with an equivalent which uses the C<CGI> module to get the upload data.
-This is convoluted and horrific and we're not going to show it here, but it's
-possible.
+C<Apache::Request> and its C<Apache::Upload> objects. If we're using
+L<CGI::Maypole> instead, we can write the action in a similar style:
+
+ sub do_upload :Exported {
+ my ($class, $r) = @_;
+ my $user = $r->user;
+ my $cgi = $r->cgi;
+ if ($cgi->upload == 1) { # if there was one file uploaded
+ my $filename = $cgi->param('picture');
+ my $ct = $cgi->upload_info($filename, 'mime');
+ return $r->error("Unknown image file type $ct")
+ if $ct !~ m{image/(jpeg|gif|png)};
+ return $r->error("File too big! Maximum size is ".MAX_IMAGE_SIZE)
+ if $cgi->upload_info($filename, 'size') > MAX_IMAGE_SIZE;
+ my $fh = $cgi->upload($filename);
+ my $image = do { local $/; <$fh> };
+ $r->user->photo_type($ct);
+ $r->user->photo($image);
+ }
+
+ $r->objects([ $user ]);
+ $r->template("view");
+ }
+
+It's easy to adapt this to upload multiple files if desired.
+You will also need to enable uploads in your driver initialization,
+with the slightly confusing statement:
+
+ $CGI::Simple::DISABLE_UPLOADS = 0; # enable uploads