我正在使用Jackrabbit Standalone 2.18.1。是否可以选择直接链接到文件以供将来使用? E.x. http://127.0.0.1:8887/rmi/myFile
。存储文件后,如果我可以收到直接链接,那将是很好的。也许我应该更改jackrabbit的配置?
这是保存文件的方式。
void saveImage(MultipartFile imageFile) throws RepositoryException, IOException {
Repository remoteRepository = new URLRemoteRepository("http://127.0.0.1:8887/rmi");
Session jackrabbitSession = remoteRepository.login(new SimpleCredentials("adm", "adm".toCharArray());
Node rootNode = jackrabbitSession.getRootNode();
Node docNode = rootNode .addNode(imageFile.getOriginalFilename(), NT_FILE);
Node contentNode = docNode.addNode(JCR_CONTENT, NT_RESOURCE);
Binary binary = rootNode.getSession().getValueFactory().createBinary(imageFile.getInputStream());
contentNode.setProperty(JCR_DATA, binary);
contentNode.setProperty(JCR_MIME_TYPE, imageFile.getContentType());
contentNode.setProperty(JCR_LAST_MODIFIED, Calendar.getInstance());
rootNode.getSession().save();
}
这就是我读取文件的方式:
InputStream readImage(String path) {
... //same connection stuff
Node docNode = rootNode .getSession().getNode(path);
Node contentNode = docNode.getNode(JCR_CONTENT);
Value value = contentNode.getProperty(JCR_DATA).getValue();
InputStream stream = value.getBinary().getStream();
return stream;
}
这很重要:
private static final String JCR_CONTENT = "jcr:content";
private static final String JCR_DATA = "jcr:data";
private static final String JCR_MIME_TYPE = "jcr:mimeType";
private static final String JCR_LAST_MODIFIED = "jcr:lastModified";
private static final String NT_RESOURCE = "nt:resource";
private static final String NT_FILE = "nt:file";