Solved

how to save a image via cgi

Posted on 1997-03-18
1
233 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now