1Catalyst::Request::UploUasde(r3)Contributed Perl DocumenCtaattailoynst::Request::Upload(3)
2
3
4
6 Catalyst::Request::Upload - handles file upload requests
7
9 my $upload = $c->req->upload('field');
10
11 $upload->basename;
12 $upload->copy_to;
13 $upload->fh;
14 $upload->decoded_fh
15 $upload->filename;
16 $upload->headers;
17 $upload->link_to;
18 $upload->size;
19 $upload->slurp;
20 $upload->decoded_slurp;
21 $upload->tempname;
22 $upload->type;
23 $upload->charset;
24
25 To specify where Catalyst should put the temporary files, set the
26 'uploadtmp' option in the Catalyst config. If unset, Catalyst will use
27 the system temp dir.
28
29 __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' );
30
31 See also Catalyst.
32
34 This class provides accessors and methods to handle client upload
35 requests.
36
38 $upload->new
39 Simple constructor.
40
41 $upload->copy_to
42 Copies the temporary file using File::Copy. Returns true for success,
43 false for failure.
44
45 $upload->copy_to('/path/to/target');
46
47 Please note the filename used for the copy target is the 'tempname'
48 that is the actual filename on the filesystem, NOT the 'filename' that
49 was part of the upload headers. This might seem counter intuitive but
50 at this point this behavior is so established that its not something we
51 can change.
52
53 You can always create your own copy routine that munges the target path
54 as you wish.
55
56 $upload->is_utf8_encoded
57 Returns true of the upload defines a character set at that value is
58 'UTF-8'. This does not try to inspect your upload and make any guesses
59 if the Content Type charset is undefined.
60
61 $upload->fh
62 Opens a temporary file (see tempname below) and returns an IO::File
63 handle.
64
65 This is a filehandle that is opened with no additional IO Layers.
66
67 $upload->decoded_fh(?$encoding)
68 Returns a filehandle that has binmode set to UTF-8 if a UTF-8 character
69 set is found. This also accepts an override encoding value that you can
70 use to force a particular PerlIO layer. If neither are found the
71 filehandle is set to :raw.
72
73 This is useful if you are pulling the file into code and inspecting
74 bits and maybe then sending those bits back as the response. (Please
75 note this is not a suitable filehandle to set in the body; use "fh" if
76 you are doing that).
77
78 Please note that using this method sets the underlying filehandle IO
79 layer so once you use this method if you go back and use the "fh"
80 method you still get the IO layer applied.
81
82 $upload->filename
83 Returns the client-supplied filename.
84
85 $upload->headers
86 Returns an HTTP::Headers object for the request.
87
88 $upload->link_to
89 Creates a hard link to the temporary file. Returns true for success,
90 false for failure.
91
92 $upload->link_to('/path/to/target');
93
94 $upload->size
95 Returns the size of the uploaded file in bytes.
96
97 $upload->slurp(?$encoding)
98 Optionally accepts an argument to define an IO Layer (which is applied
99 to the filehandle via binmode; if no layer is defined the default is
100 set to ":raw".
101
102 Returns a scalar containing the contents of the temporary file.
103
104 Note that this will cause the filehandle pointed to by "$upload->fh" to
105 be reset to the start of the file using seek and the file handle to be
106 put into whatever encoding mode is applied.
107
108 $upload->decoded_slurp(?$encoding)
109 Works just like "slurp" except we use "decoded_fh" instead of "fh" to
110 open a filehandle to slurp. This means if your upload charset is UTF8
111 we binmode the filehandle to that encoding.
112
113 $upload->basename
114 Returns basename for "filename". This filters the name through a
115 regexp "basename =~ s|[^\w\.-]+|_|g" to make it safe for filesystems
116 that don't like advanced characters. This will of course filter UTF8
117 characters. If you need the exact basename unfiltered use
118 "raw_basename".
119
120 $upload->raw_basename
121 Just like "basename" but without filtering the filename for characters
122 that don't always write to a filesystem.
123
124 $upload->tempname
125 Returns the path to the temporary file.
126
127 $upload->type
128 Returns the client-supplied Content-Type.
129
130 $upload->charset
131 The character set information part of the content type, if any. Useful
132 if you need to figure out any encodings on the file upload.
133
134 meta
135 Provided by Moose
136
138 Catalyst Contributors, see Catalyst.pm
139
141 This library is free software. You can redistribute it and/or modify it
142 under the same terms as Perl itself.
143
144
145
146perl v5.36.0 2022-07-31 Catalyst::Request::Upload(3)