jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Buchmann <da...@liip.ch>
Subject Re: Storing a file's content with JCR2.0
Date Thu, 03 Mar 2011 07:14:39 GMT
hi fabian,

i think the right way to do this is to use the ValueFactory.createBinary
method:

http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/ValueFactory.html

to get that factory, you just have to ask the session, see
http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/Session.html#getValueFactory()

cheers,
david

Am 02.03.2011 20:24, schrieb Fabián Mandelbaum:
> Hello, with JCR1.0, I've done something like this to store file
> streams (the file's binary data itself):
> 
> node.setProperty("jcr:data", new AutoCloseInputStream(new
> FileInputStream(file)));
> 
> where AutoCloseInputStream is from Commons-IO.
> 
> I've read everywhere that I have to use the new Binary 'type' (it's
> actually an Interface, so it's not instantiable) to store files now.
> I've read everywhere how to READ the streams
> (node.getProperty("jcr:data").getBinary().getStream()), but nowhere (I
> could find at least...) how to WRITE the streams to the content
> repository (that is, how to set the jcr:data property of the
> nt:resource node of the nt:file node).
> 
> I've found out that with JackRabbit I can do the following:
> 
> Binary data = new BinaryImpl(new AutoCloseInputStream(new
> FileInputStream(file)));
> node.setProperty("jcr:data", data);
> data.dispose();
> 
> which is great... except there's BinaryImpl, which is JackRabbit-specific.
> 
> Now, I don't think I'll ever use a different JCR2.0 repository
> implementation, but I'd like to know how to store files in a way
> that's repository implementation agnostic with JCR2.0 and JackRabbit
> 2.2.4 (the JCR 1.0 method was repository implementation agnostic, all
> APIs used to store the binary values where from JCR 1.0 spec itself).
> 
> Any pointer to docs or examples regarding this are appreciated as much
> as a concrete code example as an answer.
> 
> Thanks.
> 

-- 
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch

Mime
View raw message