source: gs3-extensions/meandre/trunk/src/cgi-bin/image-server.pl@ 28597

Last change on this file since 28597 was 28597, checked in by davidb, 9 years ago

CGI script for loading and savimg image-data from a chromagram

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!C:\Perl64\bin\perl.exe -w
2
3use gsdlCGI;
4
5sub load_gsdl_utils
6{
7 my ($gsdlhome) = @_;
8
9 require "$gsdlhome/perllib/util.pm";
10## require "$gsdlhome/perllib/FileUtils.pm";
11}
12
13sub save_image_data
14{
15 my ($gsdl_cgi,$io_dir,$docid,$imagedata) = @_;
16
17 if (!defined $imagedata || ($imagedata =~ m/^\s*$/)) {
18 $gsdl_cgi->generate_error("No image data given.\n");
19 return;
20 }
21
22# my $filename = &FileUtils::FileConcatenate($io_dir,"$docid-canvas.png");
23 my $filename = &util::filename_cat($io_dir,"$docid-canvas.png");
24
25
26 if (!open(FILE, ">$filename")) {
27 $gsdl_cgi->generate_error("Cannot open $filename: $!\n");
28 return;
29 }
30
31 binmode(FILE);
32
33 print FILE $imagedata;
34
35 close(FILE);
36
37 print STDOUT "Content-type:text/plain\n\n";
38 print STDOUT "Data save successful\n";
39 print STDOUT " -> Wrote image data out to $filename\n";
40
41}
42
43
44
45sub load_image_data
46{
47 my ($gsdl_cgi,$io_dir,$docid) = @_;
48
49# my $filename = &FileUtils::FileConcatenate($io_dir,"$docid-canvas.png");
50 my $filename = &util::filename_cat($io_dir,"$docid-canvas.png");
51
52 if (!open(FILE, "<$filename")) {
53 print STDERR "Requested image data file does not exist\n";
54 exit -1;
55 }
56
57 binmode(FILE);
58
59 print STDOUT "Content-type:text/plain\n\n";
60
61 while (defined ($line = <FILE>)) {
62 print $line;
63 }
64
65 close(FILE);
66
67}
68
69
70
71
72sub main
73{
74 #my $gsdl_cgi = new gsdlCGI("+cmdline"); # doesn't work anymore
75 my $gsdl_cgi = new gsdlCGI();
76
77 $gsdl_cgi->setup_gsdl();
78 my $gsdlhome = $ENV{'GSDL3HOME'};
79
80 $gsdl_cgi->checked_chdir($gsdlhome);
81
82 my $action = $gsdl_cgi->clean_param("a");
83 my $collect = $gsdl_cgi->clean_param("c");
84 my $docoid = $gsdl_cgi->clean_param("d");
85 my $site = $gsdl_cgi->clean_param("site");
86
87 ##my $io_dir = &FileUtils::FilenameConcatenate($gsdlhome,"site",$site,"collect",$collect,"index");
88 my $io_dir = &util::filename_cat($gsdlhome,"sites",$site,"collect",$collect,"index");
89
90 if ($action eq "save") {
91 my $image_data = $gsdl_cgi->clean_param("imagedata");
92 save_image_data($gsdl_cgi,$io_dir,$docoid,$image_data);
93 }
94 elsif ($action eq "load") {
95 load_image_data($gsdl_cgi,$io_dir,$docoid);
96 }
97 else {
98 $gsdl_cgi->generate_error("Unrecognized action: '$action'\n");
99 }
100
101 # filename is now local to the current dir after checked_dir
102 # my $filename = $gsdl_cgi->clean_param("filename");
103
104 # my $checksum = generate_checksum($filename,$gsdl_cgi);
105
106
107}
108
109&main();
110
Note: See TracBrowser for help on using the repository browser.