jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Lukin <lu...@stu.cn.ua>
Subject Re: download binary content
Date Tue, 11 Dec 2007 07:03:12 GMT
Monday 10 December 2007 21:50:48 wdlcs написав:
> Hi all, I would like to know it's possible to get the download URL of a
> binary content in the content repository, (My repository content is a
> PostgreSQL database).
> Thanks in advance.

First, you must create right node for binary content. It's hard to find in the 
docs so there's code:

      //pn is parent node you already created
      Node fn = pn.addNode("MyFile.jpg", "nt:file");
      fn.addMixin("mix:referenceable"); //we need UUID of this attachment 
      Node resource = fn.addNode("jcr:content","nt:resource");
      resource.setProperty("jcr:mimeType", "file/jpeg");
      //get binary data from some file on local fs 
      resource.setProperty("jcr:data", new FileInputStream(f));
      Calendar lastModified = Calendar.getInstance ();
      lastModified.setTimeInMillis (f.lastModified ());
      resource.setProperty("jcr:lastModified", lastModified);

After that you can acces this node by any browser or webdav client using URL 
like:  http://myhost/myapp/repository/default/PathToMyFiles/MyFile.jpg 
SimpleWebDav servlet from jackrabbit distro must be enabled ofcourse.
SY, Alex Lukin

View raw message