jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vibhu Sharma <vi...@projectoffguard.com>
Subject Re: Storing and retrieving images from jackrabbit
Date Sun, 03 Jan 2010 07:36:22 GMT
Hi,

I think the problem lies in retrieval.

your node addition code creates the following node structure

root <-- attachment <-- 'filename' --- prop-'jcr:data'

when you retrieve you check for

root <-- attachment --- prop-'jcr:data'

Solution:
fileNode = sourceNode.getNode(<FileName>);
fileNode.getProperty("jcr:data").getStream();

Hope this solves the problem

regards
Vibhu
projectoffguard.com

-

On Fri, Jan 1, 2010 at 4:01 PM, test123456 <sajith.pc@thinkcoretech.com>wrote:

>
> Hi new to jackrabbit.
>
> I try to create a content repository to store the  images uploaded by users
> from my web application.
>
> I am having the environment
> Tomcat 6.0.13 server
> JDK 1.6
> Jackrabbit 1.6
>
>
> I am using the following code snippet for that for adding image
>
>
>                        Node rootNode = session.getRootNode();
>                        String fileName = "abc.gif";
>                        String destinationNodeName = "attachment";
>
>                        // First check the type of the file to add
>                        MimeTable mt = MimeTable.getDefaultTable();
>                        String mimeType = mt.getContentTypeFor(fileName);
>                        if (mimeType == null)
>                        {
>                                mimeType = "application/octet-stream";
>                        }
>
>                        // Get the destinationNode to which the file to be
> added
>                        Node destinationNode =
> rootNode.addNode(destinationNodeName);
>                        Node file = destinationNode.addNode(fileName,
> "nt:file");
>                        Node contentNode = file.addNode("jcr:content",
> "nt:resource");
>
>                        // Make a stream object using the file path
>                        InputStream fileStream = new
> FileInputStream(filePath);
>
>                        // set the mandatory properties
>                        contentNode.setProperty("jcr:data", fileStream);
>                        contentNode.setProperty("jcr:lastModified",
> Calendar.getInstance());
>                        contentNode.setProperty("jcr:mimeType", mimeType);
>
>                        session.save();
>                        System.out.println("File "+ fileName + "added to the
> Node "+
> destinationNodeName + " in the repository");
>
>                        It is printing the message "File abc.gif added to
> the Node attachment in
> the repository" in the console.
>
> I used the following code snippet for diaplying image in jsp page
>
>
>
>
>                        Node rootNode = session.getRootNode();
>
>                        Striing sourceNodeName = "attachment";
>
>                        Node sourceNode = rootNode.getNode(sourceNodeName);
>
>                        if(sourceNode != null)
>                        {
>                                fileStream =
> sourceNode.getProperty("jcr:data").getStream(); // throws
> javax.jcr.PathNotFoundException: jcr:data in this line
>
>                        }
>
>
>                What will be reason for the exception.
>
> I am attached my repository.xml
>                 http://n4.nabble.com/file/n991766/repository.xmlrepository.xml
> http://n4.nabble.com/file/n991766/repository.xml repository.xml
> --
> View this message in context:
> http://n4.nabble.com/Storing-and-retrieving-images-from-jackrabbit-tp991766p991766.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message