[opencms-dev] Access a file by uuid

Yves Glodt yg at mind.lu
Mon Dec 22 13:11:37 CET 2008


On Monday 22 December 2008, Yves Glodt wrote:
> Hello again,
>
> I can also access the file by path, it will be ok for my application...
> I have this jsp, which is called logo.jpg.jsp:
>
>
> <%@ page session="true" import="org.opencms.main.*,
> org.opencms.jsp.*,org.opencms.file.*,org.opencms.util.*" %>
> <%@ page import="java.util.*" %>
> <%@ page import="java.io.*" %>
> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
> <%
>
> CmsObject cmso = OpenCms.initCmsObject("Guest");
> cmso.loginUser("user", "pass");
> CmsResource res =
> cmso.readResource("/sites/my.site.com/data/123/logo.jpg"); CmsFile file =
> new CmsFile(res);
> response.setContentLength(file.getLength());
>
> OutputStream o = response.getOutputStream();
> o.write(file.getContents());
> o.flush();
> o.close();
>
> %>
>
> But somehow it ouputs 0 bytes, even I know that the file has 8009 bytes (I
> checked by writing it to System.out) The user has access, I tried as admin
> but it makes no difference
>
> What can be wrong here ?

I found out that file.getContents() returns a byte[] of length 0

What can be the reason of this?

System.out.println("Length1: "+file.getLength());
-> 8009
byte[] temp = file.getContents();
System.out.println("Length2: "+temp.length);
-> 0



> On Monday 22 December 2008, Sebastian Himberger wrote:
> > Hi,
> >
> > I currently have no idea about the UUID thing.
> >
> > Regarding the input stream: You can simply do a:
> >
> > InputStream is = new ByteArrayInputStream(cmsFile.getContents());
> >
> > best regards,
> > Sebastian
> >
> > Yves Glodt schrieb:
> > > On Thursday 11 December 2008, Sebastian Himberger wrote:
> > >> Hi,
> > >>
> > >> this works for me:
> > >>
> > >> <%@ page
> > >> import="org.opencms.file.*,org.opencms.jsp.*,org.opencms.util.*,org.op
> > >>en cms .main.*" %>
> > >> <%
> > >>
> > >> String uuid = "ceece147-3144-11dc-a69a-5f50d3bd539c";
> > >>
> > >> CmsObject cmso = OpenCms.initCmsObject("Guest");
> > >> cmso.loginUser("Admin", "thePassWord");
> > >>
> > >> CmsResource res = cmso.readResource(new CmsUUID(uuid));
> > >>
> > >> out.println(res.getName());
> > >>
> > >> %>
> > >>
> > >> Are you sure the user who logs in has read access to the resource?
> > >
> > > Well, I guess to...
> > >
> > > I am getting this exception:
> > > org.opencms.file.CmsVfsResourceNotFoundException: Error reading
> > > resource with the ID aec33c59-c50d-11dd-a9f2-0015174f605e.
> > >
> > > Note that this works:
> > > CmsResource res =
> > > cmso.readResource("/sites/my.site.com/data/123/logo.jpg");
> > > //System.out.println(res.getResourceId().toString());
> > >
> > >
> > > And this not:
> > >
> > > CmsResource res = cmso.readResource(new CmsUUID("aec33c59-c50d-11dd-
> > > a9f2-0015174f605e"));
> > >
> > > So I guess my user is ok. The uuid I use is the one I saw in the print
> > > output of the previous example...
> > >
> > > Another question came up.... how can I output this CmsResource which is
> > > image/jpg from the jsp? Is it possible to cast it to a FileInputStream
> > > ?
> > >
> > > Best regards,
> > > Yves
> > >
> > >> best regards,
> > >> Sebastian
> > >>
> > >> Yves Glodt schrieb:
> > >>> Hello,
> > >>>
> > >>>
> > >>> is it possible to find and access a file in the VFS by it's uuid?
> > >>>
> > >>>
> > >>> Background: I have certains PDF documents in my vfs which are not
> > >>> accessible
> > >>> for any user, logged in or not, and I want to serve them with
> > >>> obfuscated urls
> > >>> à la /getFile.jsp?id=xxxxxx and it would be nice if I could just use
> > >>> the uuid
> > >>> to identify them.
> > >>> I use OpenCms 7.0.4. Maybe there is another way to achieve this...?
> > >>> :-)
> > >>>
> > >>>
> > >>> Best regards,
> > >>> Yves
> > >
> > > _______________________________________________
> > > This mail is sent to you from the opencms-dev mailing list
> > > To change your list options, or to unsubscribe from the list, please
> > > visit http://lists.opencms.org/mailman/listinfo/opencms-dev
> >
> > _______________________________________________
> > This mail is sent to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the list, please
> > visit http://lists.opencms.org/mailman/listinfo/opencms-dev
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev






More information about the opencms-dev mailing list