?
Solved

how to save a image via cgi

Posted on 1997-03-18
1
Medium Priority
?
244 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
[X]
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
1 Comment
 

Accepted Solution

by:
alanw earned 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

762 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