You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by test123456 <sa...@thinkcoretech.com> on 2010/01/01 13:01:59 UTC

Image attachment problem

I am adding a image to the jackrabbit repository.
I am using jackrabbit 1.6.0 version .

While try to retrieve the image from the repository  it is throwing the
PathNotFoundException for jcr:data

It is showing only two properties 
jcr:created
jcr:primaryType

there is no jcr:data property.

What will be the problem 
I used the following snippet for adding the image to repository

                        Node folder =
session.getRootNode().addNode("ptattachment");
			
			Node file = folder.addNode(fileName, "nt:file");
						
			MimeTable mt = MimeTable.getDefaultTable();
			String mimeType = mt.getContentTypeFor(fileName);
			if (mimeType == null) mimeType = "application/octet-stream";
			
			Node contentNode = file.addNode("jcr:content", "nt:resource");
			contentNode.setProperty("jcr:data", fileStream);
			contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
			contentNode.setProperty("jcr:mimeType", mimeType);
			
			session.save();

And used following code to retrieve the image
node = session.getRootNode().getNode("ptattachment");
InputStream in = n.getProperty("jcr:data").getStream();

-- 
View this message in context: http://n4.nabble.com/Image-attachment-problem-tp991776p991776.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Image attachment problem

Posted by test123456 <sa...@thinkcoretech.com>.
Thank you very much Mat.

I got my mistake. Your code snippet explains the problem.
And it was worked fine also.

On Fri, Jan 1, 2010 at 7:30 PM, Mat Lowery-2 [via Jackrabbit] <
ml-node+991794-1824138349@n4.nabble.com<ml...@n4.nabble.com>
> wrote:

> The storing looks fine but the retrieval looks wrong.  Try this:
>
> Node resourceNode =
> session.getRootNode().getNode("ptattachment").getNode(fileName).getNode("jcr:content");
>
> InputStream in = resourceNode.getProperty("jcr:data").getStream();
>
> On Fri, 2010-01-01 at 04:01 -0800, test123456 wrote:
>
> > I am adding a image to the jackrabbit repository.
> > I am using jackrabbit 1.6.0 version .
> >
> > While try to retrieve the image from the repository  it is throwing the
> > PathNotFoundException for jcr:data
> >
> > It is showing only two properties
> > jcr:created
> > jcr:primaryType
> >
> > there is no jcr:data property.
> >
> > What will be the problem
> > I used the following snippet for adding the image to repository
> >
> >                         Node folder =
> > session.getRootNode().addNode("ptattachment");
> >
> > Node file = folder.addNode(fileName, "nt:file");
> >
> > MimeTable mt = MimeTable.getDefaultTable();
> > String mimeType = mt.getContentTypeFor(fileName);
> > if (mimeType == null) mimeType = "application/octet-stream";
> >
> > Node contentNode = file.addNode("jcr:content", "nt:resource");
> > contentNode.setProperty("jcr:data", fileStream);
> > contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
> > contentNode.setProperty("jcr:mimeType", mimeType);
> >
> > session.save();
> >
> > And used following code to retrieve the image
> > node = session.getRootNode().getNode("ptattachment");
> > InputStream in = n.getProperty("jcr:data").getStream();
> >
>
>
>
>
> ------------------------------
>  View message @
> http://n4.nabble.com/Image-attachment-problem-tp991776p991794.html
> To unsubscribe from Image attachment problem, click here< (link removed) =>.
>
>
>

-- 
View this message in context: http://n4.nabble.com/Image-attachment-problem-tp991776p998058.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Image attachment problem

Posted by Mat Lowery <ml...@pentaho.com>.
The storing looks fine but the retrieval looks wrong.  Try this:

Node resourceNode =
session.getRootNode().getNode("ptattachment").getNode(fileName).getNode("jcr:content");
InputStream in = resourceNode.getProperty("jcr:data").getStream();

On Fri, 2010-01-01 at 04:01 -0800, test123456 wrote:

> I am adding a image to the jackrabbit repository.
> I am using jackrabbit 1.6.0 version .
> 
> While try to retrieve the image from the repository  it is throwing the
> PathNotFoundException for jcr:data
> 
> It is showing only two properties 
> jcr:created
> jcr:primaryType
> 
> there is no jcr:data property.
> 
> What will be the problem 
> I used the following snippet for adding the image to repository
> 
>                         Node folder =
> session.getRootNode().addNode("ptattachment");
> 			
> 			Node file = folder.addNode(fileName, "nt:file");
> 						
> 			MimeTable mt = MimeTable.getDefaultTable();
> 			String mimeType = mt.getContentTypeFor(fileName);
> 			if (mimeType == null) mimeType = "application/octet-stream";
> 			
> 			Node contentNode = file.addNode("jcr:content", "nt:resource");
> 			contentNode.setProperty("jcr:data", fileStream);
> 			contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
> 			contentNode.setProperty("jcr:mimeType", mimeType);
> 			
> 			session.save();
> 
> And used following code to retrieve the image
> node = session.getRootNode().getNode("ptattachment");
> InputStream in = n.getProperty("jcr:data").getStream();
> 



Re: Image attachment problem

Posted by ANoorulAmeen <no...@gmail.com>.
I tried with this example , and got the same exception.The problem in
getNode("pattachment");Use Below linenode =
session.getRootNode().getNode("ptattachment/fileName/jcr:content");



--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Image-attachment-problem-tp991776p4657025.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.