struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eva Sager <Eva.Sa...@aelera.com>
Subject RE: Problems with FormFile.getInputStream()
Date Thu, 06 Mar 2003 18:20:08 GMT
Any Suggestions???

-----Original Message-----
From: Eva Sager [mailto:Eva.Sager@aelera.com]
Sent: Wednesday, March 05, 2003 10:33 AM
To: 'Struts Users Mailing List'
Subject: RE: Problems with FormFile.getInputStream()


I tried it, with no success...  I am not having any trouble creating the
MimeMessage at all, that is all working fine, it is getting the FormFile
into a MimeBodyPart that I am having trouble with. 

In my first attempt I tried to create the MimeBodyPart using the constructor
that takes in an InputStream and use FormFile.getInputStream().  That works
to some extent in that it does produce a MimebodyPart that I can add the
MimeMessage, but it isn't the entire file I uploaded.  It is like the first
part of the file is lost in transition.  

When I tried to use the DataHandler as you suggest, it can't find the
FormFile, which isn't actually a file after all, so I wasn't sure it would
work.  I tried to just pass the name of the FormFile in as a String (which I
didn't think would work, but it was worth a try).

It seems like I came really close the first time, but I must be missing
something somewhere.  The fact that the InputStream coming out of the
FormFile is a different size than the InputStream coming out of the
MimeBodyPart makes me think that I am doing something wrong.  The file that
ends up being attached is the correct file, it is just that the top portion
of it is cut off...

Thanks,

-----Original Message-----
From: alexj [mailto:alexj@freesurf.ch]
Sent: Wednesday, March 05, 2003 9:31 AM
To: Struts Users Mailing List
Subject: Re: Problems with FormFile.getInputStream()


nop it's didn't will solve your trouble...

----- Original Message -----
From: "alexj" <alexj@freesurf.ch>
To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
Sent: Wednesday, March 05, 2003 3:27 PM
Subject: Re: Problems with FormFile.getInputStream()


> Hi try that :
>
>
> //Message
> MimeMessage mensaje = new MimeMessage(session);
>                        mensaje.setFrom(new InternetAddress(from));
>                        InternetAddress[] address = {new
> InternetAddress(TO)};//where TO is an email address
>
>                        mensaje.setRecipients(Message.RecipientType.TO,
> address);
>                        mensaje.setSubject(subject);
>                        mensaje.setSentDate(new Date());
>
>
>
> if (attach.length()!=0)
> {
> // Text
> MimeBodyPart text = new MimeBodyPart();
> Text.setText(Body);
> MimeBodyPart Bin = new MimeBodyPart();
> DataSource mySource = new FileDataSource (attach);
>
> //Binary
> Bin.setDataHandler(new DataHandler(mySource));
> Bin.setFileName(attach);
> // Join and Seending
> MimeMultipart multiple = new MimeMultipart();
> multiple.addBodyPart(Text);
> multiple.addBodyPart(Bin);
> mensaje.setContent(multiple);
>
> --
> Alexandre Jaquet
>
> ----- Original Message -----
> From: "Eva Sager" <Eva.Sager@aelera.com>
> To: "Struts Users Mailing List (E-mail)" <struts-user@jakarta.apache.org>
> Sent: Wednesday, March 05, 2003 3:21 PM
> Subject: Problems with FormFile.getInputStream()
>
>
> > I am using a file tag to upload a file and that seems to be working
fine.
> I
> > then want to email that file as an attachment and that is where I start
to
> > run into trouble.  I am then trying to make a MimeBodyPart with the
> > InputStream of the FormFile and the resulting file isn't complete.  It
is
> as
> > if the first part of the file is lost.  I have a Vector of FormFiles
that
> I
> > am working with:
> >
> >               MimeBodyPart[] attachments = new
> > MimeBodyPart[form.getAttachments().size()];
> >               for(int i=0;i<form.getAttachments().size();i++)
> >               {
> >                    FormFile file =
> > (FormFile)form.getAttachments().elementAt(i);
> >
> >                    //printing out the size and first charcter of the io
> > stream from the FormFile
> >                    log.debug("size of formfile="+file.getFileSize());
> >                    log.debug("start
> > formfile="+file.getInputStream().read());
> >
> >                    attachments[i] = new
> MimeBodyPart(file.getInputStream());
> >                    attachments[i].setFileName(file.getFileName());
> >
attachments[i].setDisposition(MimeBodyPart.ATTACHMENT);
> >
> >                    //printing out the size and first charcter of the io
> > stream from the BodyPart
> >                    log.debug("size of body
> part="+attachments[i].getSize());
> >                    log.debug("start of body
> > part="+attachments[i].getInputStream().read());
> >
> >               }
> >
> > The resulting MimeBodyPart appears to be only a portion of the original
> > file, and the logging produced supports this.
> >
> > size of formfile=1914
> > start formfile=84
> > size of body part=1717
> > start of body part=67
> >
> > I am at a loose at to what I am doing wrong...  any assistance would be
> > appreciated.
> >
> > Thanks,
> > Eva
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message