commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Joseph Olaes" <cont...@olaes.net>
Subject [FileUpload] Question re Sample Code for MultipartStream class (what is OutputStream output for?)
Date Fri, 23 Jul 2004 17:51:47 GMT
Hello List,

This is my first email post to the group.

My question regarding the example code listed at the top of the
MultipartStream class javadoc page: What is OutputStream output for? Is
it for the "out" variable? I'm getting an error with my current code
saying I have to initialize it... how do I do this? I was reading
through the javadoc and supposedly readBodyData(OutputStream) is
supposed to give the outputstream a value, but is there some kind of
initialization I have to do before hand? Like point the OutputStream
towards the "out" variable somehow?

 I've messed around with the example correcting the errors and stuff,
declaring variables and giving them instances, and I just want to get
something that works on Tomcat so I can fiddle with it and see what the
different functions do. So far I have:

<%@ page session="false" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<pre>
<%
if(FileUpload.isMultipartContent(request)){
  // request is a multipart/form-data,
javax.servlet.http.HttpServletRequest Interface Object
  out.println("lalala");

  //Enumeration eHeaderNames = new Enumeration;
  
  InputStream input = request.getInputStream(); // new InputStream();
  byte[] boundary = new byte[4096];
  
  String header;

  try {
    MultipartStream multipartStream = new MultipartStream(input,
boundary);
    boolean nextPart = multipartStream.skipPreamble();
    OutputStream output;
    PrintWriter pw = new PrintWriter(output);
    
    while(nextPart) {
      header = multipartStream.readHeaders();
      // process headers


      // create some output stream
      multipartStream.readBodyData(output);
      nextPart = multipartStream.readBoundary();
    }
  }
  catch(MultipartStream.MalformedStreamException e) {
    // the stream failed to follow required syntax
  } catch(IOException e) {
    // a read or write error occurred
  }
}
%>
</pre>
<html>
  <body>
    <form method="post" action="upload-test.jsp"
enctype="multipart/form-data">
      <input type="text" name="something" value="<%=
request.getParameter("something") %>" /><br />
      <input type="text" name="something1" value="<%=
request.getParameter("something1") %>" /><br />
      <input type="text" name="something2" value="<%=
request.getParameter("something2") %>" /><br />
      <input type="file" name="myfileupload" /><br />
      <input type="submit" />
    </form>
    <a href="upload-test.jsp">rest</a>
  </body>
</html>

What I'm trying to do ultimately is get the file in myfileupload to
upload a text file which I will later parse, but I can't get the file
upload to work so I'm trying to figure out how to get that part going.

What I've resorted to is starting with this example code, correcting
errors, defining variables before the code piece runs, and just
generally trying to get something working. I'm hoping to get help from
this mailing list, but if not I will keep looking through the javadocs
and fumbling my way through the darkness.

Thanks in advance for the help!

-TJ



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message