commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mart...@apache.org>
Subject Re: FileUpload parseRequest
Date Wed, 03 Dec 2003 18:32:10 GMT
On Wed, 3 Dec 2003, Parmley, Scott C. wrote:

> Greetings.
>
> I am trying to use FileUpload 1.0 to handle multipart requests.  I followed the HowTo
on FileUpload.  Everything seems to work ok until I get to parseRequest(request).  No exception
is thrown and the resulting list size is 0.  Therefore, hasNext() (Iterator) fails from the
get go.  Is there something I am missing here?

Seems odd. A couple of things to check:

1) Does it make any difference if you don't mess with the value before
submitting the file? For example, don't use 'onclick', but just submit the
form directly.

2) In what environment are you invoking this method? Are you sure that
some other piece of code has not already parsed (and therefore consumed)
the input stream before you try to process it?

--
Martin Cooper


>
> Thanks in advance,
> -Scott
>
>
> Environment:  JBoss+Jetty 3.2.1
>                      Windows 2k
>                      JDK 1.4.2
>
>
>
> HTML Sample:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <title>Attachment Manager</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <style type="text/css">
> <!--
> body {
>  margin-left: 0px;
>  margin-top: 0px;
>  margin-right: 0px;
>  margin-bottom: 0px;
> }
> -->
> </style>
> <link href="include/styles.css" rel="stylesheet" type="text/css">
> <script language="Javascript">
>              function processUpload() {
>                 var raw = document.forms[0].elements[3].value;
>
>                 var rar = raw.split("\\");
>                 alert("File Name: "+rar[rar.length-1]);
>                 document.attachmentsForm.fileName.value = rar[rar.length-1];
>                 document.attachmentsForm.submit();
>              }
> </script>
> </head>
>
> <body>
> <table width="100%"  border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">
>   <tr bordercolor="#92AEEB" bgcolor="#92AEEB">
>     <td colspan="2" bgcolor="#92AEEB" class="gridItem"><strong>Attachments</strong></td>
>   </tr>
>   <tr>
>     <td width="3%" align="center" bordercolor="#FFFFFF"><div align="right"><img
src="images/delete.gif" width="20" height="20"></div></td>
>     <td width="97%" bordercolor="#FFFFFF" class="gridItem"><a href="#_">IssueTemplate.html</a></td>
>   </tr>
>   <tr>
>     <td width="3%" align="center" bordercolor="#FFFFFF"><div align="right"><img
src="images/delete.gif" width="20" height="20"></div></td>
>     <td width="97%" bordercolor="#FFFFFF" class="gridItem"><a href="#_">paradigm-logo.gif</a></td>
>   </tr>
> </table>
>
> <form action=" http://localhost:8080/issue/attachment-proc" method="post" enctype="multipart/form-data"
name="attachmentsForm" class="gridItem" id="attachmentsForm">
>   <div align="center">Upload:
>     <input type="hidden" name="fileName">
>     <input type="hidden" name="action" value="write">
>   <input type="hidden" name="issueID" value="9648">
>     <input name="uploadFile" type="file" class="gridItem">
>     <input type="button" name="Upload" value="Upload" class="gridItem" onClick="processUpload();">
>   </div>
> </form>
>
> </body>
> </html>
>
>
> Java Sample:
> [...]
>
>     public void writeUpload(HttpServletRequest request) {
>         try {
>   DiskFileUpload fbase = new DiskFileUpload();
>
>                 fbase.setSizeMax(10000);
>                 fbase.setSizeThreshold(10000);
>                 fbase.setRepositoryPath(location);
>
>   if(fbase.isMultipartContent(request)) {
>                     System.out.println("IS MULITPART....HANDLING.");
>                     List fitems = fbase.parseRequest(request);
>
>
>
>                     Iterator fit = fitems.iterator();
>                     String issueID = new String();
>                     String fileName = new String();
>
>                     while(fit.hasNext()) {
>                         FileItem f = (FileItem)fit.next();
>                         if(f.isFormField()) {
>                             String a = f.getFieldName();
>
>                             if(a.equals("issueID")) {
>                                 issueID = f.getString();
>                                 System.out.println("IssueID: "+issueID);
>                             }
>                             else if(a.equals("fileName")) {
>                                 fileName = f.getString();
>                                 System.out.println("FileName: "+fileName);
>                             }
>                         }
>                         else {
>                             System.out.println("Attachment Name: "+f.getName());
>                             System.out.println("Type: "+f.getContentType());
>                             f.write(new File(location+File.separator+issueID+File.separator+fileName));
>                         }
>                     }
>                 }
>                 else {
>                     System.out.println("NOT MULTIPART!");
>                 }
>
>  }
>  catch(Exception e) {
>   e.printStackTrace();
>  }
>     }
>

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