/
Upload.pm
122 lines (84 loc) · 2.98 KB
/
Upload.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# See bottom of file for license and copyright information
=begin TML
---+!! package Foswiki::Request::Upload
Class to encapsulate uploaded file info.
=cut
package Foswiki::Request::Upload;
use v5.14;
use Assert;
use IO::File ();
use Moo;
use namespace::clean;
extends qw(Foswiki::Object);
has headers => ( is => 'ro', );
has filename => ( is => 'ro', );
has size => ( is => 'ro', );
has contentType => ( is => 'ro', );
has basename => ( is => 'ro', );
has tmpname => ( is => 'ro', );
=begin TML
---++ ClassMethod new( [ headers => \%headers, ] [ tmpname => $tmpname, ] )
Constructs a Foswiki::Request::Upload object
=cut
# Note to developers; please undef *all* fields in the object explicitly,
# whether they are references or not. That way this method is "golden
# documentation" of the live fields in the object.
sub DEMOLISH {
my $this = shift;
#SMELL: Note: untaint filename. Taken from CGI.pm
# (had to be updated for OSX in Dec2008)
$this->tmpname =~ m{^([a-zA-Z0-9_\+ \'\":/.\$\\~-]+)$};
my $file = $1;
if ( scalar( unlink($file) ) != 1 ) {
ASSERT( 0, "unable to unlink $file : $!" ) if DEBUG;
Foswiki::Exception::Fatal->throw(
text => "unable to unlink $file : $!" );
}
}
=begin TML
---++ ObjectMethod uploadInfo() -> $headers
Returns a hashref to information about uploaded
file as sent by browser.
=cut
sub uploadInfo {
return $_[0]->headers;
}
=begin TML
---++ ObjectMethod handle() -> ( $fh )
Returns an open filehandle to uploaded file.
=cut
sub handle {
my $fh = new IO::File( $_[0]->tmpname, '<' );
binmode $fh;
return $fh;
}
=begin TML
---++ ObjectMethod tmpFileName() -> ( $tmpName )
Returns the names of temporarly created file.
=cut
sub tmpFileName {
return $_[0]->tmpname;
}
1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
and TWiki Contributors. All Rights Reserved. TWiki Contributors
are listed in the AUTHORS file in the root of this distribution.
This module is based/inspired on Catalyst framework. Refer to
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7010/lib/Catalyst.pm
for credits and liscence details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.