[Bio] / FigWebServices / cluster_stage.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/cluster_stage.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Sat Feb 26 04:25:27 2005 UTC revision 1.3, Sun Feb 27 14:06:19 2005 UTC
# Line 29  Line 29 
29      exit;      exit;
30  }  }
31    
32    if (0)
33    {
34    warn "Environment:\n";
35    for my $k (sort keys(%ENV))
36    {
37        warn "$k=$ENV{$k}\n";
38    }
39    
40    warn "Params:\n";
41    for my $k ($cgi->param())
42    {
43        warn "$k=" . $cgi->param($k) . "\n";
44    }
45    }
46    
47  my $fig = new FIG;  my $fig = new FIG;
48  my $job_id = $cgi->param("job_id");  my $job_id = $cgi->param("job_id");
49  my $work_id = $cgi->param("work_id");  my $work_id = $cgi->param("work_id");
50    my $filename = $cgi->param("file");
51    
52  $job_id =~ /^\d+/ or fail "Invalid job_id\n";  $job_id =~ /^\d+/ or fail "Invalid job_id\n";
53  $work_id =~ /^\d+/ or fail "Invalid work_id\n";  $work_id =~ /^\d+/ or fail "Invalid work_id\n";
54    
55    #
56    # If filename has been give, we're uploading. Otherwise
57    # this is a download.
58    
59  my $c = new Cluster::Broker($fig);  my $c = new Cluster::Broker($fig);
60    
61    if ($filename ne "")
62    {
63        warn "Doing upload\n";
64        eval {
65            do_upload($c, $fig, $job_id, $work_id, $filename);
66        };
67        if ($@)
68        {
69            fail "upload failed: $@";
70        }
71    }
72    else
73    {
74        warn "Doing download\n";
75        do_download($c, $fig, $job_id, $work_id);
76    }
77    
78    sub do_upload
79    {
80        my($c, $fig, $job_id, $work_id, $filename) = @_;
81    
82        warn " UPLOAD: jobid=$job_id work_id=$work_id filename=$filename\n";
83    
84        #
85        # Determine location of output file.
86        #
87    
88        my $output_fh = $c->open_output_file($job_id, $work_id, $filename);
89    
90        #
91        # File is passed as the cgi parameter named "file".
92        #
93        my $fh = $cgi->upload('file');
94        warn "Got fh $fh\n";
95    
96        my($n, $buf);
97        while ($n = read($fh, $buf, 4096))
98        {
99            print $output_fh $buf;
100        }
101        close($fh);
102        close($output_fh);
103    
104        print $cgi->header(-type => "text/plain");
105        print "File uploaded OK\n";
106    }
107    
108    sub do_download
109    {
110        my($c, $fig, $job_id, $work_id) = @_;
111    
112  my ($fh, $size, $basename);  my ($fh, $size, $basename);
113    
114  my $ok = eval {  my $ok = eval {
# Line 60  Line 130 
130  }  }
131    
132  close($fh);  close($fh);
133    }
134    
135    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3