How can I preview a PDF file in the browser when selected in a table in Cuba.
I have managed to save multible files and the Entity is presented in table. The file is saved in file storage.
When I select row in table and press button for show the pdf file I got an error that says:
type Exception report
message com.vaadin.server.ServiceException: com.haulmont.cuba.core.global.RemoteException:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.vaadin.server.ServiceException: com.haulmont.cuba.core.global.RemoteException:
---
java.lang.RuntimeException: An error occurred while loading file
---
com.haulmont.cuba.core.global.FileStorageException: File not found: 11437f07-187a-3035-c91f-c38e989a8bad
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:371)
com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:254)
com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:163)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:108)
com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:95)
root cause
com.vaadin.server.ServiceException: com.haulmont.cuba.core.global.RemoteException:
---
java.lang.RuntimeException: An error occurred while loading file
---
com.haulmont.cuba.core.global.FileStorageException: File not found: 11437f07-187a-3035-c91f-c38e989a8bad
com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1464)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1421)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:369)
com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:254)
com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:163)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:108)
com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:95)
root cause
com.haulmont.cuba.core.global.RemoteException:
---
java.lang.RuntimeException: An error occurred while loading file
---
com.haulmont.cuba.core.global.FileStorageException: File not found: 11437f07-187a-3035-c91f-c38e989a8bad
com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:83)
sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:620)
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:609)
org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
com.sun.proxy.$Proxy155.downloadFile(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
com.haulmont.cuba.core.sys.remoting.LocalServiceInvokerImpl.invoke(LocalServiceInvokerImpl.java:84)
com.haulmont.cuba.web.sys.remoting.LocalServiceProxy$LocalServiceInvocationHandler.invoke(LocalServiceProxy.java:130)
com.sun.proxy.$Proxy46.downloadFile(Unknown Source)
com.haulmont.cuba.gui.export.FileDataProvider.downloadLocally(FileDataProvider.java:85)
com.haulmont.cuba.gui.export.FileDataProvider.provide(FileDataProvider.java:75)
com.haulmont.cuba.web.gui.components.WebEmbedded.lambda$setSource$690bcdf2$1(WebEmbedded.java:132)
com.vaadin.server.StreamResource.getStream(StreamResource.java:143)
com.vaadin.server.GlobalResourceHandler.handleRequest(GlobalResourceHandler.java:111)
com.vaadin.server.communication.SessionRequestHandler.handleRequest(SessionRequestHandler.java:63)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:369)
com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:254)
com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:163)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:108)
com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:95)
The code for open file for preview is as following:
Set<DocumentEntity> selected = documentsTable.getSelected();
FileDescriptor fileDescriptor = selected.iterator().next();
pdfViewer.setSource(String.format("pdf-preview%s.pdf", fileDescriptor.getUuid()), new FileDataProvider(fileDescriptor));