You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Henry Lu <zh...@umich.edu> on 2002/02/22 21:01:29 UTC

Re: Thanks Eddie.

Thanks Eddie, it work fine now!


---------------------------------------------------------------------------
Henry Lu
MCIT                                            phone: (734) 936-2063
University of Michigan Medical Center           fax:   (734) 763-4372

On Fri, 22 Feb 2002, Eddie Bush wrote:

> I uploaded graphics just fine just now.  My code is slightly different than
> yours.  I simply call the getFileData() method of FormFile to return the
> data, and write it all out at once.  Then flush the buffer and close the
> file.
>
> Try something along the lines of:
>
> FormFile ff = ... get the FormFile field
>
> FileOutputStream fos = new FileOutputStream("/some/path/" +
> ff.getFileName());
>
> fos.write(ff.getFileData());
> fos.flush();
> fos.close();
>
> If you still have problems let us know.  I have to warn you, however, that
> people don't seem to care about file uploads.  I asked for help and never
> got it.  Of course my mistakes were because I was new, and a small amount of
> experimentation got me where I needed to go, but it's still annoying to be
> totally ignored.
>
> Hope that helps!  Let us know if it does not.
>
> Eddie
>
> ----- Original Message -----
> From: "Serge A. Redchuk" <bi...@mail.ru>
> To: <st...@jakarta.apache.org>
> Sent: Friday, February 22, 2002 2:17 AM
> Subject: PLEASE, HELP !!! upload problem
>
>
> > Hello All !
> >
> > I use the Struts v.1.0.2
> >
> > Unfortunatelly I can't realize file uploading.
> >
> > And the most confusing that I have 2 different errors on different
> > files with the same code.
> >
> > Here's my form:
> >
> > <html:form action="/addImage.do" enctype="multipart/form-data" >
> > <html:hidden property="pkPartner" />
> > <html:file property="imgFile" />
> > <br>
> > <html:submit property="submit" value="Save" />
> > <html:reset/>
> > </html:form>
> >
> > Here's form bean:
> > ...
> > public final class ImagesPartnerForm extends ActionForm {
> >   private String pkPartner = null;
> >   private FormFile imgFile = null;
> >   ...
> >   public FormFile getImgFile(){
> >     return this.imgFile;
> >   }
> >   public void setImgFile( FormFile imgFile ){
> >     this.imgFile = imgFile;
> >   }
> >   public void reset( ActionMapping mapping, HttpServletRequest request ){
> >     pkPartner = (String)request.getAttribute( "pkPartner" );
> >     imgFile = null;
> >   }
> > ...
> >
> > Here's action that handles form data:
> > public final class AddImage extends ActionExt {
> >   public ActionForward perform( ActionMapping mapping, ActionForm form,
> >          HttpServletRequest request, HttpServletResponse response, String
> userName )
> >     throws IOException, ServletException
> >   {
> >     String subpath = "/partner";
> >     String targetDir = ResourceHandler.getProperty( "global",
> >       "pictures.dyn.abs-root" ) + subpath;
> >     String dbPath = ResourceHandler.getProperty( "global",
> >       "pictures.dyn.rel-root" ) + subpath;
> >     ImagesPartnerForm iform = (ImagesPartnerForm)form;
> >     FormFile ff = iform.getImgFile();
> >     //
> >     String name = ff.getFileName();
> >     String targetFile = targetDir + "/" + name;
> >     String dbFile = dbPath + "/" + name;
> >     // Save file to filesystem
> >     java.io.DataInputStream dis = new java.io.DataInputStream(
> >       ff.getInputStream() );
> >     java.io.DataOutputStream dos = new java.io.DataOutputStream(
> >       new java.io.FileOutputStream( targetFile ) );
> >     for( int i = 0; i < ff.getFileSize(); i++ ){
> >       dos.writeByte( dis.readByte() );
> >     }
> >     dos.flush();
> >     dos.close();
> >     dis.close();
> >
> >     return new ActionForward( "/jsp/partner/test.jsp" );
> >   }
> > }
> >
> > ERRORS:
> > 0) short text file was uploaded without any corruption, but:
> >
> > 1) One jpeg file was uploaded, but had less size then source.
> >
> > 2) Other jpeg file uploading caused an exception:
> >
> > javax.servlet.ServletException: IOException while reading file element:
> Premature end of stream while reading multipart request
> >         at
> org.apache.struts.upload.MultipartIterator.getNextElement(MultipartIterator.
> java:222)
> >         at
> org.apache.struts.upload.DiskMultipartRequestHandler.handleRequest(DiskMulti
> partRequestHandler.java:76)
> >         at
> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735)
> >         at
> org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:20
> 61)
> >         at
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
> >         at
> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Thanks Eddie.

Posted by Eddie Bush <ek...@swbell.net>.
Glad to have helped =)

----- Original Message -----
From: "Henry Lu" <zh...@umich.edu>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, February 22, 2002 2:01 PM
Subject: Re: Thanks Eddie.


> Thanks Eddie, it work fine now!
>
>
> --------------------------------------------------------------------------
-
> Henry Lu
> MCIT                                            phone: (734) 936-2063
> University of Michigan Medical Center           fax:   (734) 763-4372
>
> On Fri, 22 Feb 2002, Eddie Bush wrote:
>
> > I uploaded graphics just fine just now.  My code is slightly different
than
> > yours.  I simply call the getFileData() method of FormFile to return the
> > data, and write it all out at once.  Then flush the buffer and close the
> > file.
> >
> > Try something along the lines of:
> >
> > FormFile ff = ... get the FormFile field
> >
> > FileOutputStream fos = new FileOutputStream("/some/path/" +
> > ff.getFileName());
> >
> > fos.write(ff.getFileData());
> > fos.flush();
> > fos.close();
> >
> > If you still have problems let us know.  I have to warn you, however,
that
> > people don't seem to care about file uploads.  I asked for help and
never
> > got it.  Of course my mistakes were because I was new, and a small
amount of
> > experimentation got me where I needed to go, but it's still annoying to
be
> > totally ignored.
> >
> > Hope that helps!  Let us know if it does not.
> >
> > Eddie
> >
> > ----- Original Message -----
> > From: "Serge A. Redchuk" <bi...@mail.ru>
> > To: <st...@jakarta.apache.org>
> > Sent: Friday, February 22, 2002 2:17 AM
> > Subject: PLEASE, HELP !!! upload problem
> >
> >
> > > Hello All !
> > >
> > > I use the Struts v.1.0.2
> > >
> > > Unfortunatelly I can't realize file uploading.
> > >
> > > And the most confusing that I have 2 different errors on different
> > > files with the same code.
> > >
> > > Here's my form:
> > >
> > > <html:form action="/addImage.do" enctype="multipart/form-data" >
> > > <html:hidden property="pkPartner" />
> > > <html:file property="imgFile" />
> > > <br>
> > > <html:submit property="submit" value="Save" />
> > > <html:reset/>
> > > </html:form>
> > >
> > > Here's form bean:
> > > ...
> > > public final class ImagesPartnerForm extends ActionForm {
> > >   private String pkPartner = null;
> > >   private FormFile imgFile = null;
> > >   ...
> > >   public FormFile getImgFile(){
> > >     return this.imgFile;
> > >   }
> > >   public void setImgFile( FormFile imgFile ){
> > >     this.imgFile = imgFile;
> > >   }
> > >   public void reset( ActionMapping mapping, HttpServletRequest
request ){
> > >     pkPartner = (String)request.getAttribute( "pkPartner" );
> > >     imgFile = null;
> > >   }
> > > ...
> > >
> > > Here's action that handles form data:
> > > public final class AddImage extends ActionExt {
> > >   public ActionForward perform( ActionMapping mapping, ActionForm
form,
> > >          HttpServletRequest request, HttpServletResponse response,
String
> > userName )
> > >     throws IOException, ServletException
> > >   {
> > >     String subpath = "/partner";
> > >     String targetDir = ResourceHandler.getProperty( "global",
> > >       "pictures.dyn.abs-root" ) + subpath;
> > >     String dbPath = ResourceHandler.getProperty( "global",
> > >       "pictures.dyn.rel-root" ) + subpath;
> > >     ImagesPartnerForm iform = (ImagesPartnerForm)form;
> > >     FormFile ff = iform.getImgFile();
> > >     //
> > >     String name = ff.getFileName();
> > >     String targetFile = targetDir + "/" + name;
> > >     String dbFile = dbPath + "/" + name;
> > >     // Save file to filesystem
> > >     java.io.DataInputStream dis = new java.io.DataInputStream(
> > >       ff.getInputStream() );
> > >     java.io.DataOutputStream dos = new java.io.DataOutputStream(
> > >       new java.io.FileOutputStream( targetFile ) );
> > >     for( int i = 0; i < ff.getFileSize(); i++ ){
> > >       dos.writeByte( dis.readByte() );
> > >     }
> > >     dos.flush();
> > >     dos.close();
> > >     dis.close();
> > >
> > >     return new ActionForward( "/jsp/partner/test.jsp" );
> > >   }
> > > }
> > >
> > > ERRORS:
> > > 0) short text file was uploaded without any corruption, but:
> > >
> > > 1) One jpeg file was uploaded, but had less size then source.
> > >
> > > 2) Other jpeg file uploading caused an exception:
> > >
> > > javax.servlet.ServletException: IOException while reading file
element:
> > Premature end of stream while reading multipart request
> > >         at
> >
org.apache.struts.upload.MultipartIterator.getNextElement(MultipartIterator.
> > java:222)
> > >         at
> >
org.apache.struts.upload.DiskMultipartRequestHandler.handleRequest(DiskMulti
> > partRequestHandler.java:76)
> > >         at
> > org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735)
> > >         at
> >
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:20
> > 61)
> > >         at
> > org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
> > >         at
> > org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
> > >         at
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
> > >         at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>