[opencms-dev] Access a file by uuid
Yves Glodt
yg at mind.lu
Thu Nov 3 09:30:05 CET 2011
On OpenCms 8 I had to adapt slightly to the new api, here the full code to
download a file by CmsUUID:
if (CmsUUID.isValidUUID(request.getParameter("id"))) {
CmsUUID uuid = new CmsUUID(request.getParameter("id"));
CmsObject cmso = OpenCms.initCmsObject("Guest");
cmso.loginUser("user", "pass");
CmsResource res = cmso.readResource(uuid);
CmsFile file = cmso.readFile(res);
response.setHeader("Content-Disposition", "attachment;
filename=\""+res.getName()+"\"");
response.setContentType("application/octet-stream");
response.setContentLength(file.getLength());
OutputStream o = response.getOutputStream();
o.write(file.getContents());
o.flush();
o.close();
}
On 22 December 2008 13:37, Yves Glodt <yg at mind.lu> wrote:
> Florian,
>
> thank you very much, everything works now, access by uuid, and output of
> the
> file as well! I owe you a beer.
>
> Best regards,
> Yves
>
> On Monday 22 December 2008, Florian Gutmann wrote:
> > Hi,
> >
> > i think you have to use:
> > CmsFile file = CmsFile.upgrade(res, cmso);
> >
> > instead of:
> > CmsFile file = new CmsFile(res);
> >
> > If you want to read files by UUID from VFS you should be sure to use the
> > correct id.
> > There are two types of id's: the structureId and the resourceId.
> > cmsObject.readResource needs the strucutureId and not the resource id!
> > If you look at those id's they are nearly identically so you can oversee
> > that difference easyly.
> >
> > Greetings,
> >
> > Florian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20111103/0bcbebf1/attachment.htm>
More information about the opencms-dev
mailing list