hi 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", "password".toCharArray()));
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(); lastModified.setTimeInMillis(file.lastModified()); resNode.setProperty("jcr:lastModified", lastModified); System.out.println("it s after saving the file."); done = true; } finally{ session.save(); session.logout(); System.out.println("there "); return done; } ----------- code to get the file is Session session = null; FileInputStream picture = null; try{ Repository repository = new TransientRepository(); session = repository.login(new SimpleCredentials("username", "password".toCharArray())); Node root = session.getRootNode(); Node userfile = root.getNode(id); Node pic = userfile.getNode("picture"); Node image = pic.getNode("jcr:content"); picture = (FileInputStream) image.getProperty("jcr:data").getValue().getStream(); if(picture == null) System.out.println("errorr in reading the file"); } finally{ session.logout(); 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.