Foros de discusión
File upload portlet
Fabio A Miranda, modificado hace 13 años.
File upload portlet
New Member Mensajes: 10 Fecha de incorporación: 13/08/09 Mensajes recientes
Hello,
I am programming a simple portlet that processes the upload of a file via a web browser.
However, the InputStream.read(request.getPortletInputStream()) always returns -1 but ContentLegth is > 0.
Can anyone provide a simple way to processes a file upload using Liferay framework ?
Thanks in advance,
fabio.
I am programming a simple portlet that processes the upload of a file via a web browser.
However, the InputStream.read(request.getPortletInputStream()) always returns -1 but ContentLegth is > 0.
Can anyone provide a simple way to processes a file upload using Liferay framework ?
Thanks in advance,
fabio.
Jim Klo, modificado hace 13 años.
RE: File upload portlet
Junior Member Mensajes: 75 Fecha de incorporación: 7/11/08 Mensajes recientes
First make sure you're posting the form with enctype="multipart/form-data".
Then assuming you're using an MVCPortlet:
<portlet:actionurl var="submitFileAction" name="submitFile">
</portlet:actionurl>
<form action="<%= submitFileAction %>" method="post" [b]enctype="multipart/form-data" [ b]>
<input type="file" id="file" name="<portlet:namespace />file" size="47" value="<%= HtmlUtil.escape(file,1) %>">
<input type="submit" value="Submit">
</form>
Then assuming you're using an MVCPortlet:
public void submitFile(ActionRequest actionRequest, ActionResponse actionResponse) throws SystemException, PortalException {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
if (uploadRequest != null) {
String submissionFileName = uploadRequest.getFileName("file");
File submissionFile = uploadRequest.getFile("file");
}
}