FileUpload Parameter Handling
I'm using commons-fileupload-1.0.jar. I'm trying to upload a file using enctype=multipart/form-data. However, I'm also passing a hidden form input element with an ID stuck in it. This ID is critical for the state of the servlet. Oddly, when I use the enctype=multipart/form-data, my HttpServletRequest no longer seems to contain the parameters usually accessible by req.getParameter(ID);. In the debugger I see that the parameter hashtable is empty. As a test I remove enctype=multipart/form-data from the form. The parameters then show up properly in the parameter map, but now the file is not accessible. Is there a way to utilize both the file uploading capability and still have access to the parameter list as it comes in as a HttpServletRequest? Thanks in advance. Adam
Re: FileUpload Parameter Handling
Regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ On Thu, 2004-10-07 at 13:59, Adam Pelletier wrote: I'm using commons-fileupload-1.0.jar. I'm trying to upload a file using enctype=multipart/form-data. However, I'm also passing a hidden form input element with an ID stuck in it. This ID is critical for the state of the servlet. Oddly, when I use the enctype=multipart/form-data, my HttpServletRequest no longer seems to contain the parameters usually accessible by req.getParameter(ID);. In the debugger I see that the parameter hashtable is empty. As a test I remove enctype=multipart/form-data from the form. The parameters then show up properly in the parameter map, but now the file is not accessible. Is there a way to utilize both the file uploading capability and still have access to the parameter list as it comes in as a HttpServletRequest? Thanks in advance. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
Are you using Struts, Adam? Michael McGrady Adam Pelletier wrote: I'm using commons-fileupload-1.0.jar. I'm trying to upload a file using enctype=multipart/form-data. However, I'm also passing a hidden form input element with an ID stuck in it. This ID is critical for the state of the servlet. Oddly, when I use the enctype=multipart/form-data, my HttpServletRequest no longer seems to contain the parameters usually accessible by req.getParameter(ID);. In the debugger I see that the parameter hashtable is empty. As a test I remove enctype=multipart/form-data from the form. The parameters then show up properly in the parameter map, but now the file is not accessible. Is there a way to utilize both the file uploading capability and still have access to the parameter list as it comes in as a HttpServletRequest? Thanks in advance. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - Original Message - From: Michael McGrady [EMAIL PROTECTED] To: Jakarta Commons Users List [EMAIL PROTECTED] Sent: Thursday, October 07, 2004 11:45 AM Subject: Re: FileUpload Parameter Handling Are you using Struts, Adam? Michael McGrady Adam Pelletier wrote: I'm using commons-fileupload-1.0.jar. I'm trying to upload a file using enctype=multipart/form-data. However, I'm also passing a hidden form input element with an ID stuck in it. This ID is critical for the state of the servlet. Oddly, when I use the enctype=multipart/form-data, my HttpServletRequest no longer seems to contain the parameters usually accessible by req.getParameter(ID);. In the debugger I see that the parameter hashtable is empty. As a test I remove enctype=multipart/form-data from the form. The parameters then show up properly in the parameter map, but now the file is not accessible. Is there a way to utilize both the file uploading capability and still have access to the parameter list as it comes in as a HttpServletRequest? Thanks in advance. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
What are you doing with commons upload? You should be able to get whatever values are present as values of parameter keys in the form. There is nothing about a multipart upload that precludes regular parameters. For example, I parse the DiskFileUpload as follows: DiskFileUpload dfu = new DiskFileUpload(); dfu.setSizeMax(fileSizeLimit); dfu.setSizeThreshold(UploadConstant.MEMORY_BUFFER_SIZE); dfu.setRepositoryPath(tmpFolder); if(encoding != null) { dfu.setHeaderEncoding(encoding); } List list = null; try { list = dfu.parseRequest(req); StdOut.log(log.development,UploadParser list = + list); } catch(FileUploadException fue) { throw new IOException(fue.getMessage()); } And my log test (StdOut) that you see here results in UploadParser list = [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] UploadParser fieldName = uploadedFile1 UploadParser fieldName = uploadedFile2 UploadParser fieldName = uploadedFile3 UploadParser fieldName = uploadedFile4 UploadParser fieldName = uploadedFile5 UploadParser fieldName = uploadedFile6 UploadParser fieldName = uploadedFile7 UploadParser fieldName = uploadedFile8 UploadParser fieldName = uploadedFile9 UploadParser fieldName = uploadedFile10 UploadParser fieldName = uploadedFile11 UploadParser fieldName = uploadedFile12 UploadParser fieldName = submit.dispatch.x UploadParser fieldName = submit.dispatch.y UploadParser fieldName = fileOp From a page that has twelve input type='file' tags. Hope this helps. Michael McGrady Adam Pelletier wrote: No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - Original Message - From: Michael McGrady [EMAIL PROTECTED] To: Jakarta Commons Users List [EMAIL PROTECTED] Sent: Thursday, October 07, 2004 11:45 AM Subject: Re: FileUpload Parameter Handling Are you using Struts, Adam? Michael McGrady Adam Pelletier wrote: I'm using commons-fileupload-1.0.jar. I'm trying to upload a file using enctype=multipart/form-data. However, I'm also passing a hidden form input element with an ID stuck in it. This ID is critical for the state of the servlet. Oddly, when I use the enctype=multipart/form-data, my HttpServletRequest no longer seems to contain the parameters usually accessible by req.getParameter(ID);. In the debugger I see that the parameter hashtable is empty. As a test I remove enctype=multipart/form-data from the form. The parameters then show up properly in the parameter map, but now the file is not accessible. Is there a way to utilize both the file uploading capability and still have access to the parameter list as it comes in as a HttpServletRequest? Thanks in advance. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
I know what you are saying about it breaking your architecture... i use a servlet that calls scripts based on a parameter, I found that using the multipart-encoding broke that. I later discovered that if I post the multipart but have my parameter on the querystring it works fine. Paul No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
I cannot see how a servlet stepping through parameter values could break an architecture. What do you mean by that? If the parameter is there, then the servlet can read it. How that could affect architecture is not clear to me. Can you guys explain what you mean? Michael McGrady Paul DeCoursey wrote: I know what you are saying about it breaking your architecture... i use a servlet that calls scripts based on a parameter, I found that using the multipart-encoding broke that. I later discovered that if I post the multipart but have my parameter on the querystring it works fine. Paul No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
I fixed my problem. My problem is that I had a Servlet that would serve up any number of Pages. The way the navigation was wired was through keys/values pairs in the parameter list (i.e. req.getParameter(ID)). So the HttpServletRequest itself would get passed down to a couple of different delgation layers. Well in DiskFileUpload the parameters are stored differently in the Parts list and then have to be iterated over. So all my code depended upon: // block 1 req.getParameter(foo); as opposed to // block 2 Iterator iter = m_req_parts.iterator(); while (iter.hasNext()) { FileItem fi = (FileItem) iter.next(); if (fi.isFormField() fi.getFieldName().equals(foo)) { return fi.getString(); } } So what I did is write an HttpServletRequestWrapper so when my code calls black 1 above, what really happens is block 2 above executes. Thanks all for the help, Adam - Original Message - From: Michael McGrady [EMAIL PROTECTED] To: Jakarta Commons Users List [EMAIL PROTECTED] Sent: Thursday, October 07, 2004 3:29 PM Subject: Re: FileUpload Parameter Handling I cannot see how a servlet stepping through parameter values could break an architecture. What do you mean by that? If the parameter is there, then the servlet can read it. How that could affect architecture is not clear to me. Can you guys explain what you mean? Michael McGrady Paul DeCoursey wrote: I know what you are saying about it breaking your architecture... i use a servlet that calls scripts based on a parameter, I found that using the multipart-encoding broke that. I later discovered that if I post the multipart but have my parameter on the querystring it works fine. Paul No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FileUpload Parameter Handling
My pleasure, Adam. I don't know who wrote the commons upload stuff, but I think they did one hell of a job. You have to study it a bit, however, because it is not entirely intuitive at first. I will tell you this, however, it really provides a wonderful base for working with multipart issues. I have a hugely efficient file upload application built on top of this functionality. Anyway, glad you are on track. These things can bedevil us. Michael McGrady Adam Pelletier wrote: I fixed my problem. My problem is that I had a Servlet that would serve up any number of Pages. The way the navigation was wired was through keys/values pairs in the parameter list (i.e. req.getParameter(ID)). So the HttpServletRequest itself would get passed down to a couple of different delgation layers. Well in DiskFileUpload the parameters are stored differently in the Parts list and then have to be iterated over. So all my code depended upon: // block 1 req.getParameter(foo); as opposed to // block 2 Iterator iter = m_req_parts.iterator(); while (iter.hasNext()) { FileItem fi = (FileItem) iter.next(); if (fi.isFormField() fi.getFieldName().equals(foo)) { return fi.getString(); } } So what I did is write an HttpServletRequestWrapper so when my code calls black 1 above, what really happens is block 2 above executes. Thanks all for the help, Adam - Original Message - From: Michael McGrady [EMAIL PROTECTED] To: Jakarta Commons Users List [EMAIL PROTECTED] Sent: Thursday, October 07, 2004 3:29 PM Subject: Re: FileUpload Parameter Handling I cannot see how a servlet stepping through parameter values could break an architecture. What do you mean by that? If the parameter is there, then the servlet can read it. How that could affect architecture is not clear to me. Can you guys explain what you mean? Michael McGrady Paul DeCoursey wrote: I know what you are saying about it breaking your architecture... i use a servlet that calls scripts based on a parameter, I found that using the multipart-encoding broke that. I later discovered that if I post the multipart but have my parameter on the querystring it works fine. Paul No, this is just a plain servlet. Another guy wrote that regular form params show up in in the DiskFileUpload. When you iterate through the values, you can test to see if they are form fields with isFormField Example:.. DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); Iterator it = files.iterator(); while(it.hasNext()){ FileItem item = (FileItem)it.next(); if(item.isFormField()){ But that still breaks my architecture - although I can get to that architecture if I have to. Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]