Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to save a image via cgi

Posted on 1997-03-18
1
241 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

828 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