File Upload problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

File Upload problem

Latha.Kamatchi
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
Reply | Threaded
Open this post in threaded view
|

Re: File Upload problem

Martin Cooper
On 7/18/05, [hidden email]
<[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] ] File Upload problem

Brian Cook
In reply to this post by Latha.Kamatchi

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


[hidden email] 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.
[hidden email]
913.345.8900


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]