Forums de discussion
Problem uploading files in MVC portlet
alex wom, modifié il y a 12 années.
Problem uploading files in MVC portlet
Regular Member Publications: 218 Date d'inscription: 04/05/09 Publications récentes
In my MVC portlet I have problems uploading files. Some time the files are uploaded with the correct extension some time without extension. I'm using the tomcat bundle and in liferay-portal-6.0.6/tomcat-6.0.29/temp after the upload I find upload_00000033, upload_00000034 ... without extension. The portlet I'm developing need to upload a zip file and it doesn't work. But some time it works ....
The view.jsp is the following.
<aui:form action="<%= contentImportURL.toString() %>" enctype="multipart/form-data" method="post">
...
<liferay-ui:message key="import_file" />
<aui:input cssClass="lfr-input-text-container" label="import-file" name=import_file" type="file" />
</aui:form>
And the action is in the following:
public void doImport(
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
try {
checkPermissions(actionRequest);
} catch (PrincipalException e) {
SessionErrors.add(actionRequest, "NotCommunityAdministrator");
}
UploadPortletRequest uploadRequest = PortalUtil
.getUploadPortletRequest(actionRequest);
String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
String type = ParamUtil.getString(uploadRequest, "type");
String templateId = ParamUtil.getString(uploadRequest, "templateId");
String structureId = ParamUtil.getString(uploadRequest, "structureId");
File importFile = uploadRequest.getFile("import_file");
File transformFile = uploadRequest.getFile("transform_file");
String importFileName = importFile.getName();
String importSet = ParamUtil.getString(uploadRequest, "import_set");
String description = ParamUtil.getString(uploadRequest, "description");
long groupId = ParamUtil.getLong(uploadRequest, "groupId");
...
The view.jsp is the following.
<aui:form action="<%= contentImportURL.toString() %>" enctype="multipart/form-data" method="post">
...
<liferay-ui:message key="import_file" />
<aui:input cssClass="lfr-input-text-container" label="import-file" name=import_file" type="file" />
</aui:form>
And the action is in the following:
public void doImport(
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
try {
checkPermissions(actionRequest);
} catch (PrincipalException e) {
SessionErrors.add(actionRequest, "NotCommunityAdministrator");
}
UploadPortletRequest uploadRequest = PortalUtil
.getUploadPortletRequest(actionRequest);
String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
String type = ParamUtil.getString(uploadRequest, "type");
String templateId = ParamUtil.getString(uploadRequest, "templateId");
String structureId = ParamUtil.getString(uploadRequest, "structureId");
File importFile = uploadRequest.getFile("import_file");
File transformFile = uploadRequest.getFile("transform_file");
String importFileName = importFile.getName();
String importSet = ParamUtil.getString(uploadRequest, "import_set");
String description = ParamUtil.getString(uploadRequest, "description");
long groupId = ParamUtil.getLong(uploadRequest, "groupId");
...
Luis Rodríguez Fernández, modifié il y a 12 années.
RE: Problem uploading files in MVC portlet
Junior Member Publications: 86 Date d'inscription: 26/06/09 Publications récentes
Hi Alex,
What you are getting is the file that your server, Apache Tomcat, generates in its "temp" directory. I had a similar problem but with struts2 portlets. As a quick solution I make a "trick" with this jQuery snippet:
And in my jsp:
And in my Action class I had just a parameter for getting the value of "fileName". Maybe it is not the best and elegant approach, but it works...
Hope it helps,
Luis
What you are getting is the file that your server, Apache Tomcat, generates in its "temp" directory. I had a similar problem but with struts2 portlets. As a quick solution I make a "trick" with this jQuery snippet:
jQuery(document).ready(function() {
jQuery('#submitYourForm').click(function() {
var element = jQuery("#file")[0];
var hidden = jQuery("#fileName")[0];
hidden.value = elemento.value;
});
});
And in my jsp:
<input type="hidden" name="nombreFichero" id="nombreFichero">
.../...
<input type="file" name="file" id="file">
<input type="submit" value="Submit File" id="submitYourForm">
And in my Action class I had just a parameter for getting the value of "fileName". Maybe it is not the best and elegant approach, but it works...
Hope it helps,
Luis