Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java_server thread: How to upload file from applet to COS servlet?


Message #1 by "Hwang, B.K." <hwang23@s...> on Wed, 2 Oct 2002 13:20:13
Hi, everybody..

I made a applet, which upload client's file to server.
It uses COS(com.oreilly.servlet) upload servlet module.

When I tested the servlet module in server with my servlet, it works fine.
But, 
if I run my applet to upload a file, following error occurred.

------------------------------------------------------------
java.io.IOException: Separation boundary was not specified
------------------------------------------------------------


The error occurred at this line in COS's "MultipartParser"..

---------------------------------------------
    private String extractBoundary(String line) {
        // Use lastIndexOf() because IE 4.01 on Win98 has been known to 
send the
        // "boundary=" string multiple times.  Thanks to David Wall for 
this fix.
        int index = line.lastIndexOf("boundary="); <== this line
        if (index == -1) {
            return null;
        }
        String boundary = line.substring(index + 9);  // 9 for "boundary="
        if (boundary.charAt(0) == '"') {
            // The boundary is enclosed in quotes, strip them
            index = boundary.lastIndexOf('"');
            boundary = boundary.substring(1, index);
        }

        // The real boundary is always preceeded by an extra "--"
        boundary = "--" + boundary;

        return boundary;
    }
---------------------------------------------


I found the fact that ..
when I use "multipart/form-data" as "Content-Type" in html' form tag, web 
server automatically append the boundary(= delimeter) string, i.e. "-------
-----------------12012133613061".

But if I use.. 
---------------------------------------------
httpconn.setRequestProperty("Content-Type", "multipart/form-data");
---------------------------------------------
in my applet, web server(in my case, TMAX JEUS) doesn't make the boundary 
string!!


Although I use ..
---------------------------------------------
httpconn.setRequestProperty("Content-Type", "multipart/form-data; 
boundary=------------------------12012133613061");
---------------------------------------------
in applet, another error occurred.

---------------------------------------------
java.io.IOException: Corrupt form data: no leading boundary
---------------------------------------------

at COS's following line..

---------------------------------------------
        // Verify that the line is the boundary
        if (!line.startsWith(boundary)) {
            throw new IOException("Corrupt form data: no leading 
boundary: " +
                                  line + " != " + boundary);
        }
---------------------------------------------


Is there anybody who completed the applet-servlet file upload?
What boundary string do I use?

I'm hanging between life and death. T.T
Somebody help me...

  Return to Index