Uploading a file to a CGI script

Discussion in 'Java' started by Rex, Apr 28, 2005.

  1. Rex

    Rex Guest

    I need to upload a file to a CGI script on a local webserver from my
    application. I'm using the following code:

    FileInputStream tInputStream = new
    FileInputStream(mtCurrentIcon);
    ByteArrayOutputStream tBuffer = new
    ByteArrayOutputStream();
    int iBytes = 0;
    // Read the file.
    while ((iBytes = tInputStream.read())!= -1) {
    tBuffer.write(iBytes);
    }

    URLConnection tConnection = (new
    URL(SERVER_HOST+"/upload.cgi")).openConnection();
    System.out.println(tConnection.getURL().getPath());
    tConnection.setUseCaches(false);
    tConnection.setDoOutput(true);
    OutputStream tOutStream = tConnection.getOutputStream();
    tOutStream.write(tBuffer.toByteArray());
    tOutStream.flush();
    tOutStream.close();
    This does not work-neither is it able to contact the server (the
    access/error logs come up empty), nor is any exception generated.
    Is there a better way?
     
    Rex, Apr 28, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    0
    Views:
    459
  2. Dung Ping
    Replies:
    10
    Views:
    1,425
    Chaddy2222
    Jan 16, 2006
  3. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    1,120
    Michael Sparks
    Jul 30, 2005
  4. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Replies:
    7
    Views:
    774
    Michael Ekstrand
    Oct 4, 2005
  5. TCook

    ASP.Net, CGI and File Uploading

    TCook, Jul 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    TCook
    Jul 22, 2006
  6. Muzammil
    Replies:
    1
    Views:
    1,723
    red floyd
    Aug 28, 2008
  7. fatted
    Replies:
    1
    Views:
    316
    Steve Grazzini
    Jul 25, 2003
  8. kath
    Replies:
    4
    Views:
    1,126
    J. Gleixner
    Apr 9, 2007
Loading...