You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Terry McBride <tt...@yahoo.com> on 2001/10/11 22:51:44 UTC
Uploading FileItem problem with some content-types tdk2.1 Win2K
I have a problem with uploaded gif (or *.doc) files
having size zero but jpg or tif are fine. I consulted
the archive. I found the thread below explaining the
same problem, a work around, and a fix notice (which I
don't experience - probably not supposed to yet :). I
tried the workaround in the archive. I also looked
through the turbine and fulcrum source code but I
don't see how content-type in FileItem could cause
this problem.
Is the problem caused by the content-type? Why? I'm
trying to understand what's going on.
<I found these in the mailing list archive>
2.1 have a bug in FileItem.write().
Here is a workaround:
FileItem file = pp.getFileItem( "fileName" );
if (file.inMemory())
{
FileWriter writer = new FileWriter( destination );
writer.write( file.getString() );
writer.close(); // Missing in FileItem.writer()
}
else
{
file.write( destination );
}
If I only knew how to make a patch I would submit
one...
Paal Hagerup
Gunter Miessbrandt wrote:
> Hi,
> I have problems with UploadService.
> When I try to upload a file FileItem
> often writes 0 bytes long file. The upload work fine
as long as the file is
> a jpg-graphic. With other extensions it doesn?t
work. Sometimes the
> jpg-files are only half loaded.
> My Turbine Version is 2.1.
>
> Here's the code that I use to upload the file:
> FileItem fileItem =
> data.getParameters().getFileItem("file");
>
fileItem.write(TurbineServlet.getRealPath("uploaded.file"));
>
> The form in the template file is with "enctype" set
to
> "multipart/form-data".
> I have searched the archives but found no answer.
>
> Thanks in advance for any help I get!
> Gunter Miessbrandt
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
turbine-user-help@jakarta.apache.org
>
>
This has now been fixed in the DefaultFileItem.java in
jakarta-turbine-fulcrum
Thanks.
FYI, you should wrap the above in a try/finally so
that you can be assured
it is closed if the write fails for some reason.
-jon
</I found these in the mailing list archive>
=====
"I'm concerned about a better world. I'm concerned about justice; I'm concerned about brotherhood; I'm concerned about truth. And when one is concerned about that, he can never advocate violence. For through violence you may murder a murderer, but you can't murder murder. Through violence you may murder a liar, but you can't establish truth. Through violence you may murder a hater, but you can't murder hate through violence. Darkness cannot put out darkness; only light can do that."
-M. L. King, Jr., 16 August 1967
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Uploading FileItem problem with some content-types tdk2.1 Win2K
Posted by Terry McBride <tt...@yahoo.com>.
Thanks I used the suggested code in my Action instead
of altering FileItem (not sure which I was supposed to
do). It now writes the file to disk, however the gif
is garbaged. Is this a problem with proprietary file
types? I've pasted the code below.
I did a diff on the UploadFile and the DownloadFile.
They differ...
$ diff nav_next.gif private/nav_next.gif
Binary files nav_next.gif and private/nav_next.gif
differ
Thanks in advance,
Terry
FileWriter writer = null;
try
{
writer = new FileWriter(fullPath +
filename);
writer.write(fileItem.getString());
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
if (writer != null)
{
writer.close();
}
}
--- Daniel Rall <dl...@finemaltcoding.com> wrote:
> This is fixed in both 2.x and 3.x CVS.
>
> try
> {
> writer = new FileWriter(file);
> writer.write(getString());
> }
> finally
> {
> if (writer != null)
> {
> writer.close();
> }
> }
>
> See http://jakarta.apache.org/site/source.html for
> how to submit
> patches in the future.
>
>
> Terry McBride <tt...@yahoo.com> writes:
>
> > I have a problem with uploaded gif (or *.doc)
> files
> > having size zero but jpg or tif are fine. I
> consulted
> > the archive. I found the thread below explaining
> the
> > same problem, a work around, and a fix notice
> (which I
> > don't experience - probably not supposed to yet
> :). I
> > tried the workaround in the archive. I also
> looked
> > through the turbine and fulcrum source code but I
> > don't see how content-type in FileItem could cause
> > this problem.
> >
> > Is the problem caused by the content-type? Why?
> I'm
> > trying to understand what's going on.
> >
> >
> > <I found these in the mailing list archive>
> >
> > 2.1 have a bug in FileItem.write().
> >
> > Here is a workaround:
> >
> > FileItem file = pp.getFileItem( "fileName" );
> > if (file.inMemory())
> > {
> > FileWriter writer = new FileWriter( destination
> );
> > writer.write( file.getString() );
> > writer.close(); // Missing in FileItem.writer()
> > }
> > else
> > {
> > file.write( destination );
> > }
> >
> > If I only knew how to make a patch I would submit
> > one...
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> turbine-user-help@jakarta.apache.org
>
=====
"I'm concerned about a better world. I'm concerned about justice; I'm concerned about brotherhood; I'm concerned about truth. And when one is concerned about that, he can never advocate violence. For through violence you may murder a murderer, but you can't murder murder. Through violence you may murder a liar, but you can't establish truth. Through violence you may murder a hater, but you can't murder hate through violence. Darkness cannot put out darkness; only light can do that."
-M. L. King, Jr., 16 August 1967
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
Re: Uploading FileItem problem with some content-types tdk2.1 Win2K
Posted by Daniel Rall <dl...@finemaltcoding.com>.
This is fixed in both 2.x and 3.x CVS.
try
{
writer = new FileWriter(file);
writer.write(getString());
}
finally
{
if (writer != null)
{
writer.close();
}
}
See http://jakarta.apache.org/site/source.html for how to submit
patches in the future.
Terry McBride <tt...@yahoo.com> writes:
> I have a problem with uploaded gif (or *.doc) files
> having size zero but jpg or tif are fine. I consulted
> the archive. I found the thread below explaining the
> same problem, a work around, and a fix notice (which I
> don't experience - probably not supposed to yet :). I
> tried the workaround in the archive. I also looked
> through the turbine and fulcrum source code but I
> don't see how content-type in FileItem could cause
> this problem.
>
> Is the problem caused by the content-type? Why? I'm
> trying to understand what's going on.
>
>
> <I found these in the mailing list archive>
>
> 2.1 have a bug in FileItem.write().
>
> Here is a workaround:
>
> FileItem file = pp.getFileItem( "fileName" );
> if (file.inMemory())
> {
> FileWriter writer = new FileWriter( destination );
> writer.write( file.getString() );
> writer.close(); // Missing in FileItem.writer()
> }
> else
> {
> file.write( destination );
> }
>
> If I only knew how to make a patch I would submit
> one...
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org