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. Advertising

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:
    396
  2. Dung Ping
    Replies:
    10
    Views:
    995
    Chaddy2222
    Jan 16, 2006
  3. Muzammil
    Replies:
    1
    Views:
    1,147
    red floyd
    Aug 28, 2008
  4. fatted
    Replies:
    1
    Views:
    150
    Steve Grazzini
    Jul 25, 2003
  5. kath
    Replies:
    4
    Views:
    657
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page