You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Albrecht Leiprecht <al...@t-online.de> on 2004/11/15 21:16:51 UTC

How to upload Images

Hi all,

I understand that

   FileItem fileItem = data.getParameters().getFileItem("file");
   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
data.getUser().getUserName() + ".jpg");

is supposed to be used for uploading content through forms in Turbine
actions.
It seems to work, with one little problem.... The image I am getting on the
server is
totally scrambled. Doesnt look like the original at all.

The above example works fine with textfiles __ignore the *jpg ;) __
I assume that i woul have to fiddle with the content type somewhere. But the
question is where and how...

Does anyone have an idea ??

kind regards
Albrecht F. Leiprecht


PS:
I am using Turbine 2.1 on Tomcat 4


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


Re: How to upload Images

Posted by Albrecht Leiprecht <al...@t-online.de>.
> If there is another way of doing it please share.

I used PHP ;-)
I was to lazy to follow it through all the way, but I am trying to write it
in Java as soon as I can.

rgds
albi

>
> ----- Original Message -----
> From: "Albrecht Leiprecht" <al...@t-online.de>
> To: "Turbine Users List" <tu...@jakarta.apache.org>; "Albrecht
> Leiprecht" <al...@t-online.de>
> Sent: Friday, December 17, 2004 11:53 AM
> Subject: Re: How to upload Images
>
>
> > Not too long ago I wrote the following email and got a couple of
> > interesting
> > answers trying to help me with the solution. Thank you all for it. Now,
I
> > found out that there is something REALLY weird going on.
> >> Hi all,
> >> I understand that
> >>
> >>    FileItem fileItem = data.getParameters().getFileItem("file");
> >>    fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> >>    data.getUser().getUserName() + ".jpg");
> >>
> >> is supposed to be used for uploading content through forms in Turbine
> >> actions It seems to work, with one little problem.... The image I am
> >> getting on the server is totally scrambled. Doesnt look like the
original
> >> at all.
> >
> > The point is, that if i use the above code with larger images (300x300)
it
> > seems to work just fine. It doesnt work with images smaller than that
for
> > some reason ... funny ...
> >
> >
> > One more thing ... i don't need a solution anymore, since i used a
> > different
> > way of uploading the images.
> >
> > rgds
> > Albrecht F. Leiprecht
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>


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


Re: How to upload Images

Posted by Tony Oslund <ao...@bevcomm.net>.
If there is another way of doing it please share.

----- Original Message ----- 
From: "Albrecht Leiprecht" <al...@t-online.de>
To: "Turbine Users List" <tu...@jakarta.apache.org>; "Albrecht 
Leiprecht" <al...@t-online.de>
Sent: Friday, December 17, 2004 11:53 AM
Subject: Re: How to upload Images


> Not too long ago I wrote the following email and got a couple of 
> interesting
> answers trying to help me with the solution. Thank you all for it. Now, I
> found out that there is something REALLY weird going on.
>> Hi all,
>> I understand that
>>
>>    FileItem fileItem = data.getParameters().getFileItem("file");
>>    fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
>>    data.getUser().getUserName() + ".jpg");
>>
>> is supposed to be used for uploading content through forms in Turbine
>> actions It seems to work, with one little problem.... The image I am
>> getting on the server is totally scrambled. Doesnt look like the original
>> at all.
>
> The point is, that if i use the above code with larger images (300x300) it
> seems to work just fine. It doesnt work with images smaller than that for
> some reason ... funny ...
>
>
> One more thing ... i don't need a solution anymore, since i used a 
> different
> way of uploading the images.
>
> rgds
> Albrecht F. Leiprecht
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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


Re: How to upload Images

Posted by Albrecht Leiprecht <al...@t-online.de>.
Not too long ago I wrote the following email and got a couple of interesting
answers trying to help me with the solution. Thank you all for it. Now, I
found out that there is something REALLY weird going on.
> Hi all,
> I understand that
>
>    FileItem fileItem = data.getParameters().getFileItem("file");
>    fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
>    data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions It seems to work, with one little problem.... The image I am
> getting on the server is totally scrambled. Doesnt look like the original
> at all.

The point is, that if i use the above code with larger images (300x300) it
seems to work just fine. It doesnt work with images smaller than that for
some reason ... funny ...


One more thing ... i don't need a solution anymore, since i used a different
way of uploading the images.

rgds
Albrecht F. Leiprecht


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


Re: How to upload Images

Posted by Tony Oslund <ao...@bevcomm.net>.
A co-worker (Steve Y.) wrote this, but I believe that this is what you are 
looking for...

He is writing it to a database blob field, but you should easily be able to 
send it to a file.

<form method="post" enctype="multipart/form-data" 
action="$link.setPage("UploadImage.vm").setAction("UploadImage")">
<div align="left">
<table summary="upload form" cellpadding="3" cellspacing="0">
 <tr>
  <td class="label">
  File Name:
  </td>
  <td class="data">
  <input type="file" size="30" name="file">
  </td>
  <td class="data">&nbsp;</td>
 </tr>
 <tr>
  <td align="left">
  <input type="submit" name="eventSubmit_doUpload" value="Upload"/>
  </td>
 </tr>
</table>
</div>
</form>

ParameterParser pp = data.getParameters();
FileItem fileItem = pp.getFileItem("file");

// im is just a user created class, replace the calls to im with your own 
calls to write the file out.

File file = fileItem.getStoreLocation();
if (file == null) {
 // The file is in memory and can be obtained this way:
 InputStream is = fileItem.getStream();
 im.insertImage(image, is);
} else {
 // The file has been written to temporary storage and can be moved to 
database:
 im.insertImageFromFile(image, file.getAbsolutePath());
}

----- Original Message ----- 
From: "Albrecht Leiprecht" <al...@t-online.de>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Monday, November 15, 2004 2:16 PM
Subject: How to upload Images


> Hi all,
>
> I understand that
>
>   FileItem fileItem = data.getParameters().getFileItem("file");
>   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions.
> It seems to work, with one little problem.... The image I am getting on 
> the
> server is
> totally scrambled. Doesnt look like the original at all.
>
> The above example works fine with textfiles __ignore the *jpg ;) __
> I assume that i woul have to fiddle with the content type somewhere. But 
> the
> question is where and how...
>
> Does anyone have an idea ??
>
> kind regards
> Albrecht F. Leiprecht
>
>
> PS:
> I am using Turbine 2.1 on Tomcat 4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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


RE: How to upload Images

Posted by ANSI Webmaster <we...@ansi.dk>.
Alright, repository didnt like my windows path, setting it to "." worked...

/Martin

-----Original Message-----
From: ANSI Webmaster [mailto:webmaster@ansi.dk] 
Sent: 28. november 2004 02:47
To: 'Turbine Users List'
Subject: RE: How to upload Images

I *think* i solved it (obviously it was in the catalina.policy file i had to
change stuff).

However I'm not getting any file from the ParameterParser?

---

<form enctype="multipart/form-data" method="POST"
action="$link.setAction('user.UploadImage').setPage('user,MyProfile.vm')">
	<input type="file" name="file1">
	<input type="submit" value="upload" />
</form>




//get the ParameterParser from RunData
ParameterParser params = data.getParameters();

//grab the FileItems available in ParameterParser
FileItem fileItem = params.getFileItem("file1");
        
if (fileItem != null)
{
    File destination = new File(Path + Id);
           
    //destination.mkdir();
    if (destination != null)
         	if (destination.createNewFile())
        		fileItem.write(destination);
        }


fileItem is null all the time, what am I doing wrong here?

/Martin


-----Original Message-----
From: ANSI Webmaster [mailto:webmaster@ansi.dk] 
Sent: 28. november 2004 01:06
To: 'Turbine Users List'
Subject: RE: How to upload Images

I've tried to get the upload to work, but im constantly met with the access
denied error.

I've setup the .java.policy file in my home dir - but I'm in doubt over what
I should choose as codebase? Is it http:// or is it file:/ ?

/Martin

-----Original Message-----
From: Tony Oslund [mailto:aoslund@bevcomm.net] 
Sent: 15. november 2004 23:32
To: Turbine Users List
Subject: Re: How to upload Images


You are correct, but there can be an additional twist.  The uploaded file 
may be in memory, or it may have been cached to disk.  The following basic 
test takes care of this.

File file = fileItem.getStoreLocation();
if (file == null) {
 // The file is in memory and can be obtained this way:
 InputStream is = fileItem.getStream();
 im.insertImage(image, is);
} else {
 // The file has been written to temporary storage and can be moved to
database:
 im.insertImageFromFile(image, file.getAbsolutePath());
}


Also the size of file that you can upload is affected by your turbine props 
settings.  If the setting is too small the upload will fail.


# Whether the files should be automatically picked up by
# ParameterParser.

services.UploadService.automatic=true

#
# The directory where files will be temporarily stored.
#
services.UploadService.repository=.

#
# The maximum size of a request that will be processed.
#
services.UploadService.size.max=104857600

#
# The maximum size of a request that will have it's elements cached in
# memory by TurbineUploadService class.
#
services.UploadService.size.threshold=10




----- Original Message ----- 
From: "David Demner" <tu...@demner.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>; "'Albrecht 
Leiprecht'" <al...@t-online.de>
Sent: Monday, November 15, 2004 3:26 PM
Subject: RE: How to upload Images


> The critical part is to set enctype to multipart/form-data in the HTML 
> form:
>
> <form method="post" enctype="multipart/form-data"
> action="$link.setPage("UploadImage.vm").setAction("UploadImage")">
>
> The rest should work as you have below.
>
> David
>
>
> -----Original Message-----
> From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de]
> Sent: Monday November 15, 2004 12:17 PM
> To: Turbine Users List
> Subject: How to upload Images
>
>
> Hi all,
>
> I understand that
>
>   FileItem fileItem = data.getParameters().getFileItem("file");
>   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions.
> It seems to work, with one little problem.... The image I am getting on 
> the
> server is
> totally scrambled. Doesnt look like the original at all.
>
> The above example works fine with textfiles __ignore the *jpg ;) __
> I assume that i woul have to fiddle with the content type somewhere. But 
> the
> question is where and how...
>
> Does anyone have an idea ??
>
> kind regards
> Albrecht F. Leiprecht
>
>
> PS:
> I am using Turbine 2.1 on Tomcat 4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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



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



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



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


RE: How to upload Images

Posted by ANSI Webmaster <we...@ansi.dk>.
I *think* i solved it (obviously it was in the catalina.policy file i had to
change stuff).

However I'm not getting any file from the ParameterParser?

---

<form enctype="multipart/form-data" method="POST"
action="$link.setAction('user.UploadImage').setPage('user,MyProfile.vm')">
	<input type="file" name="file1">
	<input type="submit" value="upload" />
</form>




//get the ParameterParser from RunData
ParameterParser params = data.getParameters();

//grab the FileItems available in ParameterParser
FileItem fileItem = params.getFileItem("file1");
        
if (fileItem != null)
{
    File destination = new File(Path + Id);
           
    //destination.mkdir();
    if (destination != null)
         	if (destination.createNewFile())
        		fileItem.write(destination);
        }


fileItem is null all the time, what am I doing wrong here?

/Martin


-----Original Message-----
From: ANSI Webmaster [mailto:webmaster@ansi.dk] 
Sent: 28. november 2004 01:06
To: 'Turbine Users List'
Subject: RE: How to upload Images

I've tried to get the upload to work, but im constantly met with the access
denied error.

I've setup the .java.policy file in my home dir - but I'm in doubt over what
I should choose as codebase? Is it http:// or is it file:/ ?

/Martin

-----Original Message-----
From: Tony Oslund [mailto:aoslund@bevcomm.net] 
Sent: 15. november 2004 23:32
To: Turbine Users List
Subject: Re: How to upload Images


You are correct, but there can be an additional twist.  The uploaded file 
may be in memory, or it may have been cached to disk.  The following basic 
test takes care of this.

File file = fileItem.getStoreLocation();
if (file == null) {
 // The file is in memory and can be obtained this way:
 InputStream is = fileItem.getStream();
 im.insertImage(image, is);
} else {
 // The file has been written to temporary storage and can be moved to
database:
 im.insertImageFromFile(image, file.getAbsolutePath());
}


Also the size of file that you can upload is affected by your turbine props 
settings.  If the setting is too small the upload will fail.


# Whether the files should be automatically picked up by
# ParameterParser.

services.UploadService.automatic=true

#
# The directory where files will be temporarily stored.
#
services.UploadService.repository=.

#
# The maximum size of a request that will be processed.
#
services.UploadService.size.max=104857600

#
# The maximum size of a request that will have it's elements cached in
# memory by TurbineUploadService class.
#
services.UploadService.size.threshold=10




----- Original Message ----- 
From: "David Demner" <tu...@demner.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>; "'Albrecht 
Leiprecht'" <al...@t-online.de>
Sent: Monday, November 15, 2004 3:26 PM
Subject: RE: How to upload Images


> The critical part is to set enctype to multipart/form-data in the HTML 
> form:
>
> <form method="post" enctype="multipart/form-data"
> action="$link.setPage("UploadImage.vm").setAction("UploadImage")">
>
> The rest should work as you have below.
>
> David
>
>
> -----Original Message-----
> From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de]
> Sent: Monday November 15, 2004 12:17 PM
> To: Turbine Users List
> Subject: How to upload Images
>
>
> Hi all,
>
> I understand that
>
>   FileItem fileItem = data.getParameters().getFileItem("file");
>   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions.
> It seems to work, with one little problem.... The image I am getting on 
> the
> server is
> totally scrambled. Doesnt look like the original at all.
>
> The above example works fine with textfiles __ignore the *jpg ;) __
> I assume that i woul have to fiddle with the content type somewhere. But 
> the
> question is where and how...
>
> Does anyone have an idea ??
>
> kind regards
> Albrecht F. Leiprecht
>
>
> PS:
> I am using Turbine 2.1 on Tomcat 4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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



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



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


RE: How to upload Images

Posted by ANSI Webmaster <we...@ansi.dk>.
I've tried to get the upload to work, but im constantly met with the access
denied error.

I've setup the .java.policy file in my home dir - but I'm in doubt over what
I should choose as codebase? Is it http:// or is it file:/ ?

/Martin

-----Original Message-----
From: Tony Oslund [mailto:aoslund@bevcomm.net] 
Sent: 15. november 2004 23:32
To: Turbine Users List
Subject: Re: How to upload Images


You are correct, but there can be an additional twist.  The uploaded file 
may be in memory, or it may have been cached to disk.  The following basic 
test takes care of this.

File file = fileItem.getStoreLocation();
if (file == null) {
 // The file is in memory and can be obtained this way:
 InputStream is = fileItem.getStream();
 im.insertImage(image, is);
} else {
 // The file has been written to temporary storage and can be moved to
database:
 im.insertImageFromFile(image, file.getAbsolutePath());
}


Also the size of file that you can upload is affected by your turbine props 
settings.  If the setting is too small the upload will fail.


# Whether the files should be automatically picked up by
# ParameterParser.

services.UploadService.automatic=true

#
# The directory where files will be temporarily stored.
#
services.UploadService.repository=.

#
# The maximum size of a request that will be processed.
#
services.UploadService.size.max=104857600

#
# The maximum size of a request that will have it's elements cached in
# memory by TurbineUploadService class.
#
services.UploadService.size.threshold=10




----- Original Message ----- 
From: "David Demner" <tu...@demner.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>; "'Albrecht 
Leiprecht'" <al...@t-online.de>
Sent: Monday, November 15, 2004 3:26 PM
Subject: RE: How to upload Images


> The critical part is to set enctype to multipart/form-data in the HTML 
> form:
>
> <form method="post" enctype="multipart/form-data"
> action="$link.setPage("UploadImage.vm").setAction("UploadImage")">
>
> The rest should work as you have below.
>
> David
>
>
> -----Original Message-----
> From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de]
> Sent: Monday November 15, 2004 12:17 PM
> To: Turbine Users List
> Subject: How to upload Images
>
>
> Hi all,
>
> I understand that
>
>   FileItem fileItem = data.getParameters().getFileItem("file");
>   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions.
> It seems to work, with one little problem.... The image I am getting on 
> the
> server is
> totally scrambled. Doesnt look like the original at all.
>
> The above example works fine with textfiles __ignore the *jpg ;) __
> I assume that i woul have to fiddle with the content type somewhere. But 
> the
> question is where and how...
>
> Does anyone have an idea ??
>
> kind regards
> Albrecht F. Leiprecht
>
>
> PS:
> I am using Turbine 2.1 on Tomcat 4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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



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


Re: How to upload Images

Posted by Tony Oslund <ao...@bevcomm.net>.
You are correct, but there can be an additional twist.  The uploaded file 
may be in memory, or it may have been cached to disk.  The following basic 
test takes care of this.

File file = fileItem.getStoreLocation();
if (file == null) {
 // The file is in memory and can be obtained this way:
 InputStream is = fileItem.getStream();
 im.insertImage(image, is);
} else {
 // The file has been written to temporary storage and can be moved to
database:
 im.insertImageFromFile(image, file.getAbsolutePath());
}


Also the size of file that you can upload is affected by your turbine props 
settings.  If the setting is too small the upload will fail.


# Whether the files should be automatically picked up by
# ParameterParser.

services.UploadService.automatic=true

#
# The directory where files will be temporarily stored.
#
services.UploadService.repository=.

#
# The maximum size of a request that will be processed.
#
services.UploadService.size.max=104857600

#
# The maximum size of a request that will have it's elements cached in
# memory by TurbineUploadService class.
#
services.UploadService.size.threshold=10




----- Original Message ----- 
From: "David Demner" <tu...@demner.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>; "'Albrecht 
Leiprecht'" <al...@t-online.de>
Sent: Monday, November 15, 2004 3:26 PM
Subject: RE: How to upload Images


> The critical part is to set enctype to multipart/form-data in the HTML 
> form:
>
> <form method="post" enctype="multipart/form-data"
> action="$link.setPage("UploadImage.vm").setAction("UploadImage")">
>
> The rest should work as you have below.
>
> David
>
>
> -----Original Message-----
> From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de]
> Sent: Monday November 15, 2004 12:17 PM
> To: Turbine Users List
> Subject: How to upload Images
>
>
> Hi all,
>
> I understand that
>
>   FileItem fileItem = data.getParameters().getFileItem("file");
>   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
> data.getUser().getUserName() + ".jpg");
>
> is supposed to be used for uploading content through forms in Turbine
> actions.
> It seems to work, with one little problem.... The image I am getting on 
> the
> server is
> totally scrambled. Doesnt look like the original at all.
>
> The above example works fine with textfiles __ignore the *jpg ;) __
> I assume that i woul have to fiddle with the content type somewhere. But 
> the
> question is where and how...
>
> Does anyone have an idea ??
>
> kind regards
> Albrecht F. Leiprecht
>
>
> PS:
> I am using Turbine 2.1 on Tomcat 4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 



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


RE: How to upload Images

Posted by David Demner <tu...@demner.com>.
The critical part is to set enctype to multipart/form-data in the HTML form:

<form method="post" enctype="multipart/form-data" 
action="$link.setPage("UploadImage.vm").setAction("UploadImage")">

The rest should work as you have below.

David


-----Original Message-----
From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de] 
Sent: Monday November 15, 2004 12:17 PM
To: Turbine Users List
Subject: How to upload Images


Hi all,

I understand that

   FileItem fileItem = data.getParameters().getFileItem("file");
   fileItem.write(TurbineServlet.getRealPath("") +"/images/" +
data.getUser().getUserName() + ".jpg");

is supposed to be used for uploading content through forms in Turbine
actions.
It seems to work, with one little problem.... The image I am getting on the
server is
totally scrambled. Doesnt look like the original at all.

The above example works fine with textfiles __ignore the *jpg ;) __
I assume that i woul have to fiddle with the content type somewhere. But the
question is where and how...

Does anyone have an idea ??

kind regards
Albrecht F. Leiprecht


PS:
I am using Turbine 2.1 on Tomcat 4


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


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