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>