jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Re: how to store images into jackrabbit repository
Date Thu, 20 Aug 2009 07:12:36 GMT

On Thu, Aug 20, 2009 at 7:00 AM, Sunil Dhage<sunil.dhage@coreobjects.com> wrote:
> I am new to jackrabbit.  I could learn how to store Strings and xml into the repository.
> I am in need of storing images into the repository.
> Can I have some example code or link to such code.

The recommended way to store images or in fact any kinds of binary
files is to use the nt:file and nt:resource node types. This is how
the content structure looks like:

    myimage.png          [nt:file]
      /jcr:content       [nt:resource]
        @jcr:mimeType     = "image/png"
        @jcr:lastModified = <last modification date>
        @jcr:data         = <binary data>

And the JCR 1.0 code to create such a file is:

    InputStream stream = ...; // the binary image data
    Node parent = ...;        // where you want to store the image

    Node image = parent.addNode("myimage.png", "nt:file");
    Node content = image.addNode("jcr:content", "nt:resource");
    content.setProperty("jcr:mimeType", "image/png");
    content.setProperty("jcr:lastModified", Calendar.getInstance());
    Value data = session.getValueFactory().createValue(stream);
    content.setProperty("jcr:data", data);

> Please suggest what repository is good in this situation.  Actually
> I thought of using Mysql.  But I could see that mysql has issues in
> storing large files.

I recommend you to take a look at the data store feature (see the wiki
for documentation) if you plan to store lots of files in your
repository. Unless you explicitly need to store all your content in an
underlying database, I recommend that you use the file-based data


Jukka Zitting

View raw message