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"> </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" <[EMAIL PROTECTED]>
To: "Turbine Users List" <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]