jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far4ever <fathimafarh...@gmail.com>
Subject reading a file from the jacrabbit repository
Date Sun, 23 Nov 2008 11:41:52 GMT

i added an image to the repository but when i tried to get it back i wont
get it. instead i seems to be null..
is it a mistake is reading the repository or isn't the file is getting save
( because there is no way of checking if the file is loaded by using the
file explorer ) 
please help.
 the code of adding the file ------
try {
            Repository repository = new TransientRepository();
            session = repository.login(new SimpleCredentials("username",

            System.out.println("File Content length - " + file.length());
            MimeTable mt = MimeTable.getDefaultTable();
            String mimeType = mt.getContentTypeFor(file.getName());

            System.out.println("MIME Type - " + mimeType);
            if (mimeType == null) {
                mimeType = "application/octet-stream";
            Node root = session.getRootNode();

            Node userFile = root.addNode(id, "nt:folder");                               
            Node fileNode = userFile.addNode("picture", "nt:file");             
            Node resNode = fileNode.addNode("jcr:content", "nt:resource");
            resNode.setProperty("jcr:mimeType", mimeType);
            resNode.setProperty("jcr:data", new FileInputStream(file));
            resNode.setProperty("jcr:encoding", "");
            Calendar lastModified = Calendar.getInstance();
            resNode.setProperty("jcr:lastModified", lastModified);
            System.out.println("it s after saving the file.");
            done = true;
        } finally{
            System.out.println("there ");
            return done;
code to get the file is

Session session = null;
         FileInputStream picture = null;
         Repository repository = new TransientRepository();
         session = repository.login(new SimpleCredentials("username",
         Node root = session.getRootNode();
         Node userfile = root.getNode(id);
         Node pic = userfile.getNode("picture");
         Node image = pic.getNode("jcr:content");
         picture = (FileInputStream)
         if(picture == null)
             System.out.println("errorr in reading the file");
         System.out.println("after reading the image");
         return picture;

View this message in context: http://www.nabble.com/reading-a-file-from-the-jacrabbit-repository-tp20645363p20645363.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

View raw message