1 | #/usr/bin/perl -w
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 |
|
---|
5 | use LWP::UserAgent;
|
---|
6 | use HTTP::Request::Common;
|
---|
7 |
|
---|
8 | use CGI::Carp qw(fatalsToBrowser);
|
---|
9 | use CGI;
|
---|
10 |
|
---|
11 | eval('require "./gsdlCGI.pm"');
|
---|
12 | if ($@)
|
---|
13 | {
|
---|
14 | print STDOUT "Content-type:text/plain\n\n";
|
---|
15 | print STDOUT "ERROR: $@\n";
|
---|
16 | exit 0;
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | sub main
|
---|
21 | {
|
---|
22 | # Setup greenstone Perl include paths so additional packages can be found
|
---|
23 | my $gsdl_cgi = gsdlCGI->new();
|
---|
24 | $gsdl_cgi->setup_gsdl();
|
---|
25 |
|
---|
26 | require talkback;
|
---|
27 |
|
---|
28 | my $rand_string;
|
---|
29 | if (defined $gsdl_cgi->param('rand_string')) {
|
---|
30 | $rand_string = $gsdl_cgi->param('rand_string');
|
---|
31 | }
|
---|
32 | else {
|
---|
33 | $rand_string = "b310f690273cdc025e5a9b49fca8eee8";
|
---|
34 | }
|
---|
35 |
|
---|
36 | my $uploadedfile;
|
---|
37 | if (defined $gsdl_cgi->param('uploadedfile')) {
|
---|
38 | $uploadedfile = $gsdl_cgi->param('uploadedfile');
|
---|
39 | }
|
---|
40 | else {
|
---|
41 | $uploadedfile = "C:\\cygwin\\tmp\\test-medium.pdf";
|
---|
42 | }
|
---|
43 |
|
---|
44 | my $talktoUploadURL;
|
---|
45 | if (defined $gsdl_cgi->param('talkbackUpload')) {
|
---|
46 | $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
|
---|
47 | }
|
---|
48 | else {
|
---|
49 | $talktoUploadURL = "http://www.nzdl.org/gsdl-new/cgi-bin/talkback-progressbar.pl";
|
---|
50 | }
|
---|
51 |
|
---|
52 | my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
|
---|
53 |
|
---|
54 | my $response = $browser->post(
|
---|
55 | $talktoUploadURL,
|
---|
56 | [ 'yes_upload' => '1',
|
---|
57 | 'process' => '1',
|
---|
58 | 'rand_string' => $rand_string,
|
---|
59 | 'uploadedfile' => [$uploadedfile, "test-medium.pdf"]
|
---|
60 | ],
|
---|
61 | 'Content_Type' => 'form-data'
|
---|
62 | );
|
---|
63 |
|
---|
64 | if ($response->is_success) {
|
---|
65 | print "Content-type:text/html\n\n";
|
---|
66 | print $response->content;
|
---|
67 | }
|
---|
68 | else {
|
---|
69 | print $response->error_as_HTML;
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | main();
|
---|
75 |
|
---|