Works fine for me. Only difference is that as in the example I read directly
from the PostFileInputStream - to rehash it here:

        int character;
        PostFileInputStream in = (PostFileInputStream)element;
        ....
        while ( (character = in.read()) > -1 ) 
        {
                        out.write( character );
        }

Your input buffering code in the snippet you show is not correct

        --peter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 29, 2001 12:27 AM
To: Orion-Interest
Subject: Upload files


I try to upload file from a jsp-page with the code below. The code retrieve
the file path with in.getFileName() but in.avaiable() is always returning 0.
I can not understand why? Can any of you help me with this problem or have
any of you done this?
Thanks in advance,
Rudi.

        Enumeration enumeration = new
FilePostParser(request.getInputStream(),
 
request.getContentLength());
        while(enumeration.hasMoreElements()){
            Object element = enumeration.nextElement();
        
          if(element instanceof Map.Entry){
                Map.Entry entry = (Map.Entry) element;
                String param = (String)entry.getKey();
        .
        .
        .
        .
        } else if (element instanceof PostFileInputStream){
                in = (PostFileInputStream)element;
                originFileName = in.getFileName();
            }

        boolean isReading = true;
        BufferedInputStream buffIn = new BufferedInputStream(in);
        byte[] buf = new byte[4 * 1024];  
        while (isReading) {
            int readByte =  buffIn.read(buf);
            out.print(" "+readByte);
            isReading = readByte != (-1);
        }
        out.println("<br>");
        buffIn.close();

and the form:
<form name="mainform"  action="submitdata.jsp" enctype="multipart/form-data"
method="post" >
        <input type="file" name="file" value="Browse...">
        <input type="submit" value="Register">
</form>

  • Upload files Rudi . Fagermo
    • SAURUGGER,PETER (A-PaloAlto,ex2)

Reply via email to