You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by nik gonzalez <ng...@exist.com> on 2005/02/23 10:04:46 UTC
File upload using commons fileuploader not working
Hello,
I ran the following code in my portlet.
PortletFileUpload dfu = new PortletFileUpload();
//get the FileItems
List fileItems = dfu.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
//pass along to render request
String fieldName = item.getFieldName();
String value = item.getString();
response.setRenderParameter(fieldName, value);
}
else
{
//write the uploaded file to a new location
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
long size = item.getSize();
response.setRenderParameter("size",
Long.toString(size));
response.setRenderParameter("contentType", contentType);
String tempDir = System.getProperty("java.io.tmpdir");
System.out.println("tempDir: "+tempDir);
String serverFileName = fieldName + "-portlet.tmp";
File serverFile = new File(tempDir, serverFileName);
item.write(serverFile);
response.setRenderParameter("serverFileName",
serverFileName);
getPortletContext().log(
"serverFileName : " + tempDir + "/" +
serverFileName);
}
}
Once i submit the multipart form, it does not enter the while loop meaning
that the iterator is empty. Is this a bug?
I attached the rest of the source code. got this from one of the messages in
this mailing list.
Thanks,
Nik
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
RE: File upload using commons fileuploader not working
Posted by nik gonzalez <ng...@exist.com>.
Christophe,
Here's my html:
<%@ page session="false" %>
<%@ page import="javax.portlet.*"%>
<%@ page import="java.util.*"%>
<%@ taglib uri='/WEB-INF/tld/portlet.tld' prefix='portlet'%>
<portlet:defineObjects/>
<form action=<portlet:actionURL/> enctype="multipart/form-data"
method="post">
<input type="file" name="foo"/><br>
<input name="method" type="submit" value="Submit"/>
</form><br>
Thanks,
Nik
> -----Original Message-----
> From: Christophe Lombart
> [mailto:christophe.lombart@sword-technologies.com]
> Sent: Friday, February 25, 2005 6:32 AM
> To: Jetspeed Users List
> Subject: Re: File upload using commons fileuploader not working
>
>
> I'm using the same component in Graffito and it works with Jetspeed 2.
> Your code seems correct. Maybe an issue in the html form.
>
> Christophe
>
> nik gonzalez wrote:
>
> >By the way, its a JSR 168 portlet that i deployed in Fusion.
> >
> >Thanks,
> >Nik
> >
> >
> >
> >>-----Original Message-----
> >>From: nik gonzalez [mailto:ngonzalez@exist.com]
> >>Sent: Wednesday, February 23, 2005 5:05 PM
> >>To: jetspeed-user@jakarta.apache.org
> >>Subject: File upload using commons fileuploader not working
> >>
> >>
> >>Hello,
> >>
> >>I ran the following code in my portlet.
> >>
> >> PortletFileUpload dfu = new PortletFileUpload();
> >> //get the FileItems
> >> List fileItems = dfu.parseRequest(request);
> >> Iterator iter = fileItems.iterator();
> >> while (iter.hasNext())
> >> {
> >> FileItem item = (FileItem) iter.next();
> >> if (item.isFormField())
> >> {
> >> //pass along to render request
> >> String fieldName = item.getFieldName();
> >> String value = item.getString();
> >> response.setRenderParameter(fieldName, value);
> >> }
> >> else
> >> {
> >> //write the uploaded file to a new location
> >> String fieldName = item.getFieldName();
> >> String fileName = item.getName();
> >> String contentType = item.getContentType();
> >> long size = item.getSize();
> >> response.setRenderParameter("size",
> >>Long.toString(size));
> >>
> >>response.setRenderParameter("contentType", contentType);
> >> String tempDir =
> >>System.getProperty("java.io.tmpdir");
> >> System.out.println("tempDir: "+tempDir);
> >> String serverFileName = fieldName +
> >>"-portlet.tmp";
> >> File serverFile = new File(tempDir,
> >>serverFileName);
> >> item.write(serverFile);
> >> response.setRenderParameter("serverFileName",
> >> serverFileName);
> >> getPortletContext().log(
> >> "serverFileName : " + tempDir + "/" +
> >>serverFileName);
> >> }
> >> }
> >>
> >>Once i submit the multipart form, it does not enter the while
> >>loop meaning
> >>that the iterator is empty. Is this a bug?
> >>
> >>I attached the rest of the source code. got this from one of
> >>the messages in
> >>this mailing list.
> >>
> >>Thanks,
> >>Nik
> >>
> >>
> >>
> >>
> >>
> >>
> >>--
> >>No virus found in this outgoing message.
> >>Checked by AVG Anti-Virus.
> >>Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
> >>
> >>
> >>
> >>--
> >>No virus found in this incoming message.
> >>Checked by AVG Anti-Virus.
> >>Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
> >>
> >>
> >>
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
>
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
Re: File upload using commons fileuploader not working
Posted by Christophe Lombart <ch...@sword-technologies.com>.
I'm using the same component in Graffito and it works with Jetspeed 2.
Your code seems correct. Maybe an issue in the html form.
Christophe
nik gonzalez wrote:
>By the way, its a JSR 168 portlet that i deployed in Fusion.
>
>Thanks,
>Nik
>
>
>
>>-----Original Message-----
>>From: nik gonzalez [mailto:ngonzalez@exist.com]
>>Sent: Wednesday, February 23, 2005 5:05 PM
>>To: jetspeed-user@jakarta.apache.org
>>Subject: File upload using commons fileuploader not working
>>
>>
>>Hello,
>>
>>I ran the following code in my portlet.
>>
>> PortletFileUpload dfu = new PortletFileUpload();
>> //get the FileItems
>> List fileItems = dfu.parseRequest(request);
>> Iterator iter = fileItems.iterator();
>> while (iter.hasNext())
>> {
>> FileItem item = (FileItem) iter.next();
>> if (item.isFormField())
>> {
>> //pass along to render request
>> String fieldName = item.getFieldName();
>> String value = item.getString();
>> response.setRenderParameter(fieldName, value);
>> }
>> else
>> {
>> //write the uploaded file to a new location
>> String fieldName = item.getFieldName();
>> String fileName = item.getName();
>> String contentType = item.getContentType();
>> long size = item.getSize();
>> response.setRenderParameter("size",
>>Long.toString(size));
>>
>>response.setRenderParameter("contentType", contentType);
>> String tempDir =
>>System.getProperty("java.io.tmpdir");
>> System.out.println("tempDir: "+tempDir);
>> String serverFileName = fieldName +
>>"-portlet.tmp";
>> File serverFile = new File(tempDir,
>>serverFileName);
>> item.write(serverFile);
>> response.setRenderParameter("serverFileName",
>> serverFileName);
>> getPortletContext().log(
>> "serverFileName : " + tempDir + "/" +
>>serverFileName);
>> }
>> }
>>
>>Once i submit the multipart form, it does not enter the while
>>loop meaning
>>that the iterator is empty. Is this a bug?
>>
>>I attached the rest of the source code. got this from one of
>>the messages in
>>this mailing list.
>>
>>Thanks,
>>Nik
>>
>>
>>
>>
>>
>>
>>--
>>No virus found in this outgoing message.
>>Checked by AVG Anti-Virus.
>>Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
>>
>>
>>
>>--
>>No virus found in this incoming message.
>>Checked by AVG Anti-Virus.
>>Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
>>
>>
>>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
RE: File upload using commons fileuploader not working
Posted by nik gonzalez <ng...@exist.com>.
By the way, its a JSR 168 portlet that i deployed in Fusion.
Thanks,
Nik
> -----Original Message-----
> From: nik gonzalez [mailto:ngonzalez@exist.com]
> Sent: Wednesday, February 23, 2005 5:05 PM
> To: jetspeed-user@jakarta.apache.org
> Subject: File upload using commons fileuploader not working
>
>
> Hello,
>
> I ran the following code in my portlet.
>
> PortletFileUpload dfu = new PortletFileUpload();
> //get the FileItems
> List fileItems = dfu.parseRequest(request);
> Iterator iter = fileItems.iterator();
> while (iter.hasNext())
> {
> FileItem item = (FileItem) iter.next();
> if (item.isFormField())
> {
> //pass along to render request
> String fieldName = item.getFieldName();
> String value = item.getString();
> response.setRenderParameter(fieldName, value);
> }
> else
> {
> //write the uploaded file to a new location
> String fieldName = item.getFieldName();
> String fileName = item.getName();
> String contentType = item.getContentType();
> long size = item.getSize();
> response.setRenderParameter("size",
> Long.toString(size));
>
> response.setRenderParameter("contentType", contentType);
> String tempDir =
> System.getProperty("java.io.tmpdir");
> System.out.println("tempDir: "+tempDir);
> String serverFileName = fieldName +
> "-portlet.tmp";
> File serverFile = new File(tempDir,
> serverFileName);
> item.write(serverFile);
> response.setRenderParameter("serverFileName",
> serverFileName);
> getPortletContext().log(
> "serverFileName : " + tempDir + "/" +
> serverFileName);
> }
> }
>
> Once i submit the multipart form, it does not enter the while
> loop meaning
> that the iterator is empty. Is this a bug?
>
> I attached the rest of the source code. got this from one of
> the messages in
> this mailing list.
>
> Thanks,
> Nik
>
>
>
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
>
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 2/22/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org