Solved

how to save a image via cgi

Posted on 1997-03-18
1
240 Views
Last Modified: 2008-03-06
Howdy, i am making an applet which can save image via CGI. I found a
GIFEnder at http://www.cs.brown.edu/people/amd/ and using it. core code is
following:
   GIFEncoder encoder;
       ByteArrayOutputStream byteOut =
         new ByteArrayOutputStream(16384);// make 16384byte
   try{
          try{
            encoder = new GIFEncoder(Img);//Img is an image in applet
            encoder.Write(byteOut);
            System.out.println("Encoder bytes:
"+byteOut.size());//i got some size!
            } catch(AWTException e){} //need for GIFEncoder
        }
        catch (IOException e)
        {}
     try {
            System.out.println("Connect output");
            URL url = new URL(getCodeBase(), "test.cgi");
            System.out.println("get url");
            URLConnection urlConnection = url.openConnection();
            urlConnection.setDoOutput(true);
            PrintStream oout = new
            PrintStream(urlConnection.getOutputStream());
            System.out.println(oout);//returns object
            oout.print(byteOut);
            oout.flush();
            oout.close();
            }
            catch (IOException e){}
           ...........
<test.cgi>
#! /usr/local/bin/perl
$file ='data.gif';
print "Content-type: image/gif\n";
print "\n";

if (defined($ENV{'CONTENT_LENGTH'})) {
  open(F,">$file");
  $len = $ENV{'CONTENT_LENGTH'};

  for ($i = 0; $i < $len; $i++) {
    $c = getc;
    print F $c;
  }
  close(F);
}

there is not any error messages. i plug in "System.out.println" and check
how the program behave.. as far as i know there is no problem but there
would not any out put in data.gif. I am not really clear whether i sould
use PRINTSTREAM to pass cgi file. i would be appreciate for any help or
some pointers in web-pages... thanks for advance.
 

0
Comment
Question by:umeda
1 Comment
 

Accepted Solution

by:
alanw earned 100 total points
ID: 1219069
I have done exactly the same.  However I never used PrintStream, I used the other one.

However, in your CGI script, you are writing too much to the file. Do not write any HTML header information to the file, and then everything should be tickety boo.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 59
hibernate example using maven 12 42
iterator/ListIterator approach 17 27
Java Restore security prompts not working 10 13
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question