commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Joseph Olaes" <>
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="*" %>
<%@ page import="java.util.*" %>
  // request is a multipart/form-data,
javax.servlet.http.HttpServletRequest Interface Object

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

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

      // create some output stream
      nextPart = multipartStream.readBoundary();
  catch(MultipartStream.MalformedStreamException e) {
    // the stream failed to follow required syntax
  } catch(IOException e) {
    // a read or write error occurred
    <form method="post" action="upload-test.jsp"
      <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" />
    <a href="upload-test.jsp">rest</a>

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!


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message