You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Sunil Dhage <su...@coreobjects.com> on 2009/08/20 07:00:37 UTC

how to store images into jackrabbit repository

Hi,

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.

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.

Thanks in anticipation.

Regards,
Sunil

FW: how to store images into jackrabbit repository

Posted by Sunil Dhage <su...@coreobjects.com>.
Can anyone help me reg the below mentioned help.

-----Original Message-----
From: Sunil Dhage [mailto:sunil.dhage@coreobjects.com]
Sent: Thursday, August 20, 2009 10:31 AM
To: users@jackrabbit.apache.org
Subject: how to store images into jackrabbit repository

Hi,

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.

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.

Thanks in anticipation.

Regards,
Sunil

Re: how to store images into jackrabbit repository

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Aug 20, 2009 at 7:00 AM, Sunil Dhage<su...@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);
    parent.save();

> 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
store.

BR,

Jukka Zitting