我在liferay工作我有这个功能:
public class NewPortlet extends MVCPortlet {
public void abc(ActionRequest arq,ActionResponse ars) throws Exception {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(arq);
FileUploader fileUp = new FileUploaderImpl();
fileUp.setFid(CounterLocalServiceUtil.increment("FileUploader.class"));
File file = (File) uploadRequest.getFile("file");
byte[] bytes = FileUtil.getBytes(file);
fileUp.setContent(Base64.objectToString(bytes));
FileUploaderLocalServiceUtil.addFileUploader(fileUp);
}
}
其中 File 属于 com.liferay.portal.kernel.util.File;我正在尝试使用上述功能上传图片。我让 UI 上传图片,当我点击提交时,我收到以下错误:
ERROR [http-bio-8080-exec-37][render_portlet_jsp:154] java.lang.ClassCastException: java.io.File cannot be cast to com.liferay.portal.kernel.util.File
at com.test.image.test.NewPortlet.abc(NewPortlet.java:25)
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:153)
at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:250)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:80)
at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:220)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:579)
我应该怎么做才能将 java.io.File 转换为 com.liferay.portal.kernel.util.File?