Foren

Upload File Portlet

Concetta Carone, geändert vor 16 Jahren.

Upload File Portlet

New Member Beiträge: 12 Beitrittsdatum: 27.11.07 Neueste Beiträge
Hi,
I'm using Lifaray 4.3.6 on server Tomcat.

I have a problem with portlet that has to allow the user to upload a file and
store it into a database.
I have tried throughout the forum but have not found anything that can help
me...It is really REALLY so much that I am trying to find a way!!!

I have deployed sample-struts-liferay-portlet-4.3.6.1.war and tried to upload
file. I got "Upload Success" message.
But I could not find where the file locates, I checked the code, and could
not figure out where the file is stored!! Can I modify the code to specify a
location for the file on disk?

Is there anyone who can help?

I saw that we have so many this type of problem, so, for all those who like me
have this ugly problem:
there is someone who can definitely provide a complete code?
He would be very kind!!!
Thanks in advance
C.C.
Concetta Carone, geändert vor 16 Jahren.

RE: Upload File Portlet

New Member Beiträge: 12 Beitrittsdatum: 27.11.07 Neueste Beiträge
Hi,

Is there a solution for portlet upload withouth struts?

I must integrate portlet upload in my portlet application (Sibecs-Liferay) that consists of portlets jsp-existing, ie I must pass it the APPLICATION SCOPE and save uploaded files in my database, and then, being fasting struts, I noticed that I would not know how to combine the two things ... indeed, for what I need, is not the right solution.

To have a portlet upload without passing by struts, the only system seems to use libraries FileUpload Apache Commons.

Carryover here:

  • upload.jsp


<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<script language="javascript">
function submitForm (form) {
form.submit();
return true;
}
</script>
<form action="<portlet:actionURL/>" method="POST" enctype="multipart/form-data">
<h3>Upload image form </h3>
<table>
<tr>
<td>Image file</td>
<td><input type="file" name="imageFile"></td>
</tr>
<tr>
<td><input type="submit" name="submit" Value="Submit"></td>
<td><input type="reset" name="Cancel" title="Cancel"></td>
</tr>
</table>
</form>


  • FileUploadPortlet.java


import java.io.*;
import java.sql.*;
import java.util.Vector;
import javax.portlet.*;

import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.portlet.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.util.*;
public class FileUploadPortlet extends GenericPortlet {
private String error;
public void doView(RenderRequest req, RenderResponse res)
throws IOException, PortletException
{
WindowState state = req.getWindowState();
res.setContentType("text/html");
PortletSession session = req.getPortletSession(true);
PortletContext context = getPortletContext();
PortletRequestDispatcher rd;
rd = context.getRequestDispatcher("/WEB-INF/jsp/upload.jsp");
rd.include(req, res);

}
public void processAction(ActionRequest req, ActionResponse res)
throws IOException, PortletException
{
PortletSession session = req.getPortletSession(true);
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
PortletFileUpload portletFileUpload = new PortletFileUpload(diskFileItemFactory);
try {

while (portletFileUpload.parseRequest(req).iterator().hasNext()) {
FileItem fileItem = (FileItem) portletFileUpload.parseRequest(req).iterator().next();
byte[] data = fileItem.get();
session.setAttribute("photo",data,PortletSession.APPLICATION_SCOPE);

}
}
catch (FileUploadException e) {
error = e.getMessage();
System.out.println("[ERRORE]: " + error);
}
}
}


But hot depoly fails!! Nor with the 4.3.4 or 4.3.6!!

10:43:53,546 ERROR [HotDeployUtil:60] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering plugins for Sibecs-Liferay
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering plugi
ns for Sibecs-Liferay
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeDeploy(PluginPackageHotDeployListener.java:194)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:85)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:42)
at com.liferay.portal.kernel.servlet.PortletContextListener.portalInit(PortletContextListener.java:45)
at com.liferay.portal.kernel.util.PortalInitableUtil.init(PortalInitableUtil.java:39)
at com.liferay.portal.kernel.servlet.PortletContextListener.contextInitialized(PortletContextListener.java:52)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: The moduleId is not correct
at com.liferay.portal.plugin.ModuleId.<init>(ModuleId.java:134)
at com.liferay.portal.plugin.ModuleId.getInstance(ModuleId.java:44)
at com.liferay.portal.plugin.PluginPackageImpl.<init>(PluginPackageImpl.java:68)
at com.liferay.portal.plugin.PluginPackageUtil.readPluginPackageXml(PluginPackageUtil.java:454)
at com.liferay.portal.plugin.PluginPackageUtil.readPluginPackageXml(PluginPackageUtil.java:444)
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.readPluginPackage(PluginPackageHotDeployListener.java:155)
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeDeploy(PluginPackageHotDeployListener.java:177)
... 21 more
10:43:53,562 INFO [PortletHotDeployListener:130] Registering portlets for Sibecs-Liferay
10:43:53,609 WARN [PortletHotDeployListener:284] Can't find bundle for base name content.Ricerca, locale en_US
10:43:53,609 WARN [PortletHotDeployListener:284] Can't find bundle for base name content.Ricerca, locale en
7-apr-2008 10.43.53 org.apache.catalina.core.StandardContext start
GRAVE: Error listenerStart
7-apr-2008 10.43.53 org.apache.catalina.core.StandardContext start
GRAVE: Context [/Sibecs-Liferay] startup failed due to previous errors
10:43:53,656 INFO [PluginPackageHotDeployListener:74] Reading plugin package for Sibecs-Liferay
10:43:53,656 ERROR [HotDeployUtil:60] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error unregistering plugins for Sibecs-Liferay
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error unregistering plugins for Sibecs-Liferay
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeUndeploy(PluginPackageHotDeployListener.java:228)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireUndeployEvent
(HotDeployUtil.java:100)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireUndeployEvent(HotDeployUtil.java:46)
at com.liferay.portal.kernel.servlet.PortletContextListener.contextDestroyed(PortletContextListener.java:56)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3866)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4500)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492
)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: The moduleId is not correct
at com.liferay.portal.plugin.ModuleId.<init>(ModuleId.java:134)
at com.liferay.portal.plugin.ModuleId.getInstance(ModuleId.java:44)
at com.liferay.portal.plugin.PluginPackageImpl.<init>(PluginPackageImpl.java:68)
at com.liferay.portal.plugin.PluginPackageUtil.readPluginPackageXml(PluginPackageUtil.java:454)
at com.liferay.portal.plugin.PluginPackageUtil.readPluginPackageXml(PluginPackageUtil.java:444)
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.readPluginPackage(PluginPackageHotDeployListener.java:155)
at com.liferay.portal.deploy.hot.PluginPackageHotDeployListener.invokeUndeploy(PluginPackageHotDeployListener.java:212)
... 20 more


Please help me!!!
Alex Kudinov, geändert vor 16 Jahren.

RE: Upload File Portlet

Junior Member Beiträge: 31 Beitrittsdatum: 14.01.08 Neueste Beiträge
make sure you configured your xml files correctly:


Caused by: java.lang.RuntimeException: The moduleId is not correct
Concetta Carone, geändert vor 16 Jahren.

RE: Upload File Portlet

New Member Beiträge: 12 Beitrittsdatum: 27.11.07 Neueste Beiträge
Thanks for your answer.
Until the inclusion of this code in my application I have no problems!

My file liferay-plugin-package.xml is:
<?xml version="1.0"?>
<!DOCTYPE plugin-package PUBLIC "-//Liferay//DTD Plugin Package 4.3.0//EN" "http://www.liferay.com/dtd/liferay-plugin-package_4_3_0.dtd">

<plugin-package>
<name>Sibecs-Liferay</name>
<module-id></module-id>
<types>
<type>portlet</type>
</types>
<short-description></short-description>
<change-log></change-log>
<page-url></page-url>
<author></author>
<licenses>
<license osi-approved="true">MIT</license>
</licenses>
<liferay-versions>
<liferay-version>4.3.4</liferay-version>
</liferay-versions>
</plugin-package>


How can I configure this?
What should I put in module-id?
Alex Kudinov, geändert vor 16 Jahren.

RE: Upload File Portlet

Junior Member Beiträge: 31 Beitrittsdatum: 14.01.08 Neueste Beiträge
module-id should be in format

<module-id><company>/<whatever-your-package-is>/<LR-version>/war</module-id>
thumbnail
Ron Bense, geändert vor 16 Jahren.

RE: Upload File Portlet

Regular Member Beiträge: 117 Beitrittsdatum: 23.08.07 Neueste Beiträge
Concetta Carone:
Thanks for your answer.
Until the inclusion of this code in my application I have no problems!

My file liferay-plugin-package.xml is:

<liferay-versions>
<liferay-version>4.3.4</liferay-version>
</liferay-versions>


How can I configure this?
What should I put in module-id?


Well, the above portion of the package description will only run on Liferay version 4.3.4. If you want it to run on all 4.3 version, make the version specification "4.3.*". I believe there's also a "+" modifier, but you'll have to confirm that.

I usually just edit it to be whatever major/minor version I'm on with a star modifier.

As for dealing with plugins, your best bet is to always look at a working plugin for format/content of the liferay specific files.
Jhansi Rani, geändert vor 12 Jahren.

RE: Upload File Portlet

Junior Member Beiträge: 32 Beitrittsdatum: 27.07.11 Neueste Beiträge
Hi Friends,

I am using same code in processAction(-,-) to upload a image, but I am getting nullPointer Exception.
I am using liferay6.0.5

Can we use the same code in liferay6.0.5 ?
or any modifications do we required to work with liferay6.0.5?

Please help me.

Thanks & Regards
Jhansi Rani P.