You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by La...@cybernetsoft.com on 2005/07/19 07:44:42 UTC
File Upload problem
Hi experts
In my application, I use commons-fileupload-1.0.jar for file upload.
In the Jsp page,
I use the <html:form action="EventDetailsForScheduler"
enctype="multipart/form-data" method="POST">.
and a file for field
<html:file name="eventdetailsform" property="imageFile" size="40"/>
In the Formbean class I have a property imageFile of Type FormFile to
capture this value.
I want the Action class to do the file uploading( I use the builtin
ActionServlet only...No customized Servlet or anything..)
In the execute Method,
I use the following code
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be
thrown
fu.setSizeMax(1000000);
List fileItems = fu.parseRequest(req);
Iterator itr = fileItems.iterator();
But the size() method of this Iterator returns zero only..ie.no file is
sent for uploading..
I tried printing the file name in the
setImageFile() method of the bean.and is correctly printing.then why it is
not retrived in the Action class?
Cannot I handle the fileuploading inside the Action class?
What cud be wrong?
Thanks in advance
Aathi
Re: [FileUpload] ] File Upload problem
Posted by Brian Cook <bc...@printtime.com>.
Ok if the iterator is returning zero items that means that either the
HttpServletRequest object was empty, or that for some reason that type
was not set to "multipart/form-data".
Are you using the .isMultipartContent(HttpServletRequest req) method to
test the HttpServletRequest to make sure that it is "multipart/form-data"?
If so you may want to check the HttpServletRequest object as soon as it
comes in to see if the fields you are posting are in it. If they are
not there is probably a syntax problem with the form and or field tags.
P.S. You may want to review the guide lines for posting to this list.
It will help you get more responses if you follow those recomendations.
http://jakarta.apache.org/site/mail.html
Latha.Kamatchi@cybernetsoft.com wrote:
> Hi experts
> In my application, I use commons-fileupload-1.0.jar for file upload.
>
> In the Jsp page,
>
> I use the <html:form action="EventDetailsForScheduler"
> enctype="multipart/form-data" method="POST">.
> and a file for field
>
> <html:file name="eventdetailsform" property="imageFile" size="40"/>
>
> In the Formbean class I have a property imageFile of Type FormFile to
> capture this value.
>
> I want the Action class to do the file uploading( I use the builtin
> ActionServlet only...No customized Servlet or anything..)
>
> In the execute Method,
> I use the following code
>
> DiskFileUpload fu = new DiskFileUpload();
> // If file size exceeds, a FileUploadException will be
> thrown
> fu.setSizeMax(1000000);
>
> List fileItems = fu.parseRequest(req);
> Iterator itr = fileItems.iterator();
>
> But the size() method of this Iterator returns zero only..ie.no file is
> sent for uploading..
>
> I tried printing the file name in the
>
> setImageFile() method of the bean.and is correctly printing.then why it is
> not retrived in the Action class?
>
> Cannot I handle the fileuploading inside the Action class?
>
> What cud be wrong?
>
> Thanks in advance
> Aathi
--
Brian Cook
Digital Services Analyst
Print Time Inc.
bcook@printtime.com
913.345.8900
Re: File Upload problem
Posted by Martin Cooper <mf...@gmail.com>.
On 7/18/05, Latha.Kamatchi@cybernetsoft.com
<La...@cybernetsoft.com> wrote:
> Hi experts
> In my application, I use commons-fileupload-1.0.jar for file upload.
>
> In the Jsp page,
>
> I use the <html:form action="EventDetailsForScheduler"
> enctype="multipart/form-data" method="POST">.
> and a file for field
>
> <html:file name="eventdetailsform" property="imageFile" size="40"/>
>
> In the Formbean class I have a property imageFile of Type FormFile to
> capture this value.
>
> I want the Action class to do the file uploading( I use the builtin
> ActionServlet only...No customized Servlet or anything..)
>
> In the execute Method,
> I use the following code
>
> DiskFileUpload fu = new DiskFileUpload();
> // If file size exceeds, a FileUploadException will be
> thrown
> fu.setSizeMax(1000000);
>
> List fileItems = fu.parseRequest(req);
> Iterator itr = fileItems.iterator();
>
> But the size() method of this Iterator returns zero only..ie.no file is
> sent for uploading..
>
> I tried printing the file name in the
>
> setImageFile() method of the bean.and is correctly printing.then why it is
> not retrived in the Action class?
>
> Cannot I handle the fileuploading inside the Action class?
Struts has file upload handling built in, so you don't need to do it
yourself. The problem you are seeing is happening because Struts has
already parsed the request and populated the form bean for you, so the
input stream has already been consumed.
All you need to do in your action is use the form items you defined.
All the uploading will have been handled already by the time your
action is invoked.
--
Martin Cooper
> What cud be wrong?
>
> Thanks in advance
> Aathi
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org