You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eva Sager <Ev...@aelera.com> on 2003/03/05 15:21:27 UTC
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
Re: Problems with FormFile.getInputStream()
Posted by alexj <al...@freesurf.ch>.
nop it's didn't will solve your trouble...
----- Original Message -----
From: "alexj" <al...@freesurf.ch>
To: "Struts Users Mailing List" <st...@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" <Ev...@aelera.com>
> To: "Struts Users Mailing List (E-mail)" <st...@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
Re: Problems with FormFile.getInputStream()
Posted by alexj <al...@freesurf.ch>.
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" <Ev...@aelera.com>
To: "Struts Users Mailing List (E-mail)" <st...@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