Using FileUpload with Struts

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

Using FileUpload with Struts

Andreas Heinecke
Hi,

I encountered a problem with commons FileUpload and Struts. I decided to use
the commons FileUpload in my struts app because the upload with struts
(FormFile) isn't serializable. I need it to be serializable because I want to
make the uploaded file persistent with hibernate.
I found out that using the commons FileUpload will be serializable, since it
implements the Interface. But how do I integrate it with struts?

Here is what I've done:

I created a multipart-form with tags by struts:
<html:form action="/admin/upload.do" enctype="multipart/form-data">
                <table>
                        <tr>
                                <td>Titel&#160;</td>
                                <td><html:text property="title" size="80" /></td>
                        </tr>
                        <tr>
                                <td>Datei&#160;</td>
                                <td><html:file property="file"></html:file> </td>
                        </tr>
                        <tr>
                                <td>&#160;</td>
                                <td
align="right"><html:reset>reset</html:reset>&#160;<html:submit>eintragen</html:submit>
                                </td>
                        </tr>
                </table>
        </html:form>

The I created to corresponding Form class:
public class UploadForm extends ValidatorForm
{
        private String title;
        private FormFile file;
       
        // getters .. and setters left out for this post

}

This form will be sent to my Action class UploadAction:

Here I am able to retrieve the FormFile ... but thats not serializable

If I try to get the uploaded file as described at FileUpload Homepage, like
this:

DiskFileUpload upload = new DiskFileUpload();
List<FileItem> items = upload.parseRequest(request);

The returned list is null.

Does anybody allready done something like that?
Any sugesstion is much appreciated!

Thx in advance,

regards

Andreas Heinecke



attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using FileUpload with Struts

Martin Cooper
The reason you're getting null returned from parseRequest() is that
the request was already parsed, and therefore consumed, by Struts
before your action was invoked. If you want to parse the request
yourself, the only way to do that is to _not_ associate an action form
with your action mapping. If there is no form bean, then Struts will
obviously not try to populate it, and it is the population process
that causes a multipart stream to be parsed by Struts. (In the old
days, there was a way to disable multipart handling, but that got lost
somewhere along the line, I'm afraid.)

--
Martin Cooper


On 7/31/05, Andreas Heinecke <[hidden email]> wrote:

> Hi,
>
> I encountered a problem with commons FileUpload and Struts. I decided to use
> the commons FileUpload in my struts app because the upload with struts
> (FormFile) isn't serializable. I need it to be serializable because I want to
> make the uploaded file persistent with hibernate.
> I found out that using the commons FileUpload will be serializable, since it
> implements the Interface. But how do I integrate it with struts?
>
> Here is what I've done:
>
> I created a multipart-form with tags by struts:
> <html:form action="/admin/upload.do" enctype="multipart/form-data">
>                 <table>
>                         <tr>
>                                 <td>Titel&#160;</td>
>                                 <td><html:text property="title" size="80" /></td>
>                         </tr>
>                         <tr>
>                                 <td>Datei&#160;</td>
>                                 <td><html:file property="file"></html:file> </td>
>                         </tr>
>                         <tr>
>                                 <td>&#160;</td>
>                                 <td
> align="right"><html:reset>reset</html:reset>&#160;<html:submit>eintragen</html:submit>
>                                 </td>
>                         </tr>
>                 </table>
>         </html:form>
>
> The I created to corresponding Form class:
> public class UploadForm extends ValidatorForm
> {
>         private String title;
>         private FormFile file;
>
>         // getters .. and setters left out for this post
>
> }
>
> This form will be sent to my Action class UploadAction:
>
> Here I am able to retrieve the FormFile ... but thats not serializable
>
> If I try to get the uploaded file as described at FileUpload Homepage, like
> this:
>
> DiskFileUpload upload = new DiskFileUpload();
> List<FileItem> items = upload.parseRequest(request);
>
> The returned list is null.
>
> Does anybody allready done something like that?
> Any sugesstion is much appreciated!
>
> Thx in advance,
>
> regards
>
> Andreas Heinecke
>
>
>
>
>

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

Reply | Threaded
Open this post in threaded view
|

Re: Using FileUpload with Struts

Andreas Heinecke
Hi Martin,

thanks for your help. I know now there will be no easy way for using the
FileItem of the commons FileUpload. I think it is some kind of strange that
the struts owned FormFile is not serializable.
So the only way to store a file will be as byte array or String or something
like that.

As said some lines ago, thanks for your help.

greetings

Andreas Heinecke

Am Sonntag, 31. Juli 2005 18:42 schrieb Martin Cooper:

> The reason you're getting null returned from parseRequest() is that
> the request was already parsed, and therefore consumed, by Struts
> before your action was invoked. If you want to parse the request
> yourself, the only way to do that is to _not_ associate an action form
> with your action mapping. If there is no form bean, then Struts will
> obviously not try to populate it, and it is the population process
> that causes a multipart stream to be parsed by Struts. (In the old
> days, there was a way to disable multipart handling, but that got lost
> somewhere along the line, I'm afraid.)
>
> --
> Martin Cooper
>
> On 7/31/05, Andreas Heinecke <[hidden email]> wrote:
> > Hi,
> >
> > I encountered a problem with commons FileUpload and Struts. I decided to
> > use the commons FileUpload in my struts app because the upload with
> > struts (FormFile) isn't serializable. I need it to be serializable
> > because I want to make the uploaded file persistent with hibernate.
> > I found out that using the commons FileUpload will be serializable, since
> > it implements the Interface. But how do I integrate it with struts?
> >
> > Here is what I've done:
> >
> > I created a multipart-form with tags by struts:
> > <html:form action="/admin/upload.do" enctype="multipart/form-data">
> >                 <table>
> >                         <tr>
> >                                 <td>Titel&#160;</td>
> >                                 <td><html:text property="title" size="80"
> > /></td> </tr>
> >                         <tr>
> >                                 <td>Datei&#160;</td>
> >                                 <td><html:file
> > property="file"></html:file> </td> </tr>
> >                         <tr>
> >                                 <td>&#160;</td>
> >                                 <td
> > align="right"><html:reset>reset</html:reset>&#160;<html:submit>eintragen<
> >/html:submit> </td>
> >                         </tr>
> >                 </table>
> >         </html:form>
> >
> > The I created to corresponding Form class:
> > public class UploadForm extends ValidatorForm
> > {
> >         private String title;
> >         private FormFile file;
> >
> >         // getters .. and setters left out for this post
> >
> > }
> >
> > This form will be sent to my Action class UploadAction:
> >
> > Here I am able to retrieve the FormFile ... but thats not serializable
> >
> > If I try to get the uploaded file as described at FileUpload Homepage,
> > like this:
> >
> > DiskFileUpload upload = new DiskFileUpload();
> > List<FileItem> items = upload.parseRequest(request);
> >
> > The returned list is null.
> >
> > Does anybody allready done something like that?
> > Any sugesstion is much appreciated!
> >
> > Thx in advance,
> >
> > regards
> >
> > Andreas Heinecke
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

[HttpClient] : How we get the number of bytes transferred via PostMethod

Nicolas Maujean
Hi,

How we get the number of bytes transferred via PostMethod ?

thanks for your answer,

Nicolas Maujean



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

Reply | Threaded
Open this post in threaded view
|

RE: [HttpClient] : How we get the number of bytes transferred via PostMethod

Nicolas Maujean
ok I found the answer don't have to look for it

>From: "Nicolas Maujean" <[hidden email]>
>Reply-To: "Jakarta Commons Users List" <[hidden email]>
>To: [hidden email]
>Subject: [HttpClient] : How we get the number of bytes transferred via
>PostMethod
>Date: Mon, 01 Aug 2005 11:09:22 +0000
>
>Hi,
>
>How we get the number of bytes transferred via PostMethod ?
>
>thanks for your answer,
>
>Nicolas Maujean
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>



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