You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by Thiwanka Wimalasuriya <th...@srilogic.com> on 2004/11/19 05:54:05 UTC
uploading files from a jsr168 portlet
dear all,
i'm trying to upload a file from a jsr168 portlet. but i'm unable to save the uploaded file.
the jsp in which i upload the file is below
--------------------------------------------------------------------------------
........
........
<%@ page import="com.srilogic.portal.portlets.jsr168.example.PersonalizationPortlet" %>
<%
RenderRequest pReq = (RenderRequest)request.getAttribute("javax.portlet.request");
RenderResponse rRes = (RenderResponse)request.getAttribute("javax.portlet.response");
PortletPreferences pref = pReq.getPreferences();
PortletURL actionURL = rRes.createActionURL();
%>
<FORM METHOD="POST" ACTION="<%=actionURL.toString()%>" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="myFile" ID="myFile">
<INPUT TYPE="SUBMIT" NAME="<%=PersonalizationPortlet.CHANGE_IMAGE%>" VALUE="changeImage">
</FORM>
--------------------------------------------------------------------------------
this is the way i tryied to get the uploaded file from the portlet class. the below is the relavent part of my "PersonalizationPortlet.java"
public void processAction(
ActionRequest request,
ActionResponse actionResponse)
throws PortletException, IOException {
//lets try to write the file some where
InputStream in = request.getPortletInputStream();
OutputStream os = new FileOutputStream("c:\\demo.out");
int i = in.read();
while (i != -1) {
os.write(i);
i = in.read();
}
os.close();
in.close();
}
}
}
--------------------------------------------------------------------------------
this will save a emply file to c:\demo.out what ever file i uplod from the jsp.
any help please
kind regards
-thiwanka
Re: uploading files from a jsr168 portlet
Posted by John West <jw...@exnihilo.com>.
err, "...find the file content." Sorry about the typo.
John West wrote:
> It's been a while since I did this, but if I remember correctly you
> need to parse each part of the request separately to find the find
> content. It's easier to use a pre-made class, and there are several of
> them.
>
> I've used both the MultipartRequest class from
> http://www.servlets.com/cos/ and the FormFile class from Struts
> successfully; FormFile in a portlet and MultipartRequest in a servlet.
>
> You should be able to use the same ideas in the portlet situation as
> you would in a servlet so a Google search would give you the exact
> answer you're looking for.
>
> Good luck.
>
>
> Thiwanka Wimalasuriya wrote:
>
>> dear all,
>>
>> i'm trying to upload a file from a jsr168 portlet. but i'm unable to
>> save the uploaded file.
>>
>> the jsp in which i upload the file is below
>>
>> --------------------------------------------------------------------------------
>>
>>
>>
>> ........
>> ........
>> <%@ page
>> import="com.srilogic.portal.portlets.jsr168.example.PersonalizationPortlet"
>> %>
>>
>>
>> <%
>> RenderRequest pReq =
>> (RenderRequest)request.getAttribute("javax.portlet.request");
>> RenderResponse rRes =
>> (RenderResponse)request.getAttribute("javax.portlet.response");
>> PortletPreferences pref = pReq.getPreferences();
>> PortletURL actionURL = rRes.createActionURL();
>> %>
>>
>>
>> <FORM METHOD="POST" ACTION="<%=actionURL.toString()%>"
>> ENCTYPE="multipart/form-data">
>> <INPUT TYPE="FILE" NAME="myFile" ID="myFile">
>> <INPUT TYPE="SUBMIT" NAME="<%=PersonalizationPortlet.CHANGE_IMAGE%>"
>> VALUE="changeImage">
>> </FORM>
>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>
>> this is the way i tryied to get the uploaded file from the portlet
>> class. the below is the relavent part of my
>> "PersonalizationPortlet.java"
>>
>> public void processAction(
>> ActionRequest request,
>> ActionResponse actionResponse)
>> throws PortletException, IOException {
>>
>> //lets try to write the file some where
>>
>> InputStream in = request.getPortletInputStream();
>> OutputStream os = new FileOutputStream("c:\\demo.out");
>>
>> int i = in.read();
>> while (i != -1) {
>> os.write(i);
>> i = in.read();
>> }
>> os.close();
>> in.close();
>>
>> }
>> }
>> }
>>
>> --------------------------------------------------------------------------------
>>
>>
>> this will save a emply file to c:\demo.out what ever file i uplod
>> from the jsp.
>>
>> any help please
>>
>>
>> kind regards
>> -thiwanka
>>
>>
>>
>>
>>
>>
>>
>
--
*John West*
ExNihilo Inc.
2 Charles St.
Providence, RI 02904
Phone 401 621.8277 ext. 25
Fax 401 454.5029
www.exnihilo.com <http://www.exnihilo.com>
Re: uploading files from a jsr168 portlet
Posted by John West <jw...@exnihilo.com>.
It's been a while since I did this, but if I remember correctly you need
to parse each part of the request separately to find the find content.
It's easier to use a pre-made class, and there are several of them.
I've used both the MultipartRequest class from
http://www.servlets.com/cos/ and the FormFile class from Struts
successfully; FormFile in a portlet and MultipartRequest in a servlet.
You should be able to use the same ideas in the portlet situation as you
would in a servlet so a Google search would give you the exact answer
you're looking for.
Good luck.
Thiwanka Wimalasuriya wrote:
>dear all,
>
>i'm trying to upload a file from a jsr168 portlet. but i'm unable to save the uploaded file.
>
>the jsp in which i upload the file is below
>
>--------------------------------------------------------------------------------
>
>
>........
>........
><%@ page import="com.srilogic.portal.portlets.jsr168.example.PersonalizationPortlet" %>
>
>
><%
>RenderRequest pReq = (RenderRequest)request.getAttribute("javax.portlet.request");
>RenderResponse rRes = (RenderResponse)request.getAttribute("javax.portlet.response");
>PortletPreferences pref = pReq.getPreferences();
>PortletURL actionURL = rRes.createActionURL();
>%>
>
>
><FORM METHOD="POST" ACTION="<%=actionURL.toString()%>" ENCTYPE="multipart/form-data">
><INPUT TYPE="FILE" NAME="myFile" ID="myFile">
><INPUT TYPE="SUBMIT" NAME="<%=PersonalizationPortlet.CHANGE_IMAGE%>" VALUE="changeImage">
></FORM>
>
>
>--------------------------------------------------------------------------------
>
>
>this is the way i tryied to get the uploaded file from the portlet class. the below is the relavent part of my "PersonalizationPortlet.java"
>
> public void processAction(
> ActionRequest request,
> ActionResponse actionResponse)
> throws PortletException, IOException {
>
> //lets try to write the file some where
>
> InputStream in = request.getPortletInputStream();
> OutputStream os = new FileOutputStream("c:\\demo.out");
>
> int i = in.read();
> while (i != -1) {
> os.write(i);
> i = in.read();
> }
> os.close();
> in.close();
>
> }
> }
> }
>
>--------------------------------------------------------------------------------
>
>this will save a emply file to c:\demo.out what ever file i uplod from the jsp.
>
>any help please
>
>
>kind regards
>-thiwanka
>
>
>
>
>
>
>
--
*John West*
ExNihilo Inc.
2 Charles St.
Providence, RI 02904
Phone 401 621.8277 ext. 25
Fax 401 454.5029
www.exnihilo.com <http://www.exnihilo.com>