Solved

how to save a image via cgi

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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