The method I posted in my previous post is not compiling. This one is better :
[code]
private void importImage(Node node, File image) throws Exception {
Session session = MgnlContext.getJCRSession("data");
MimetypesFileTypeMap mtftm = new MimetypesFileTypeMap();
InputStream is = new FileInputStream(image);
Node nodeImage = node.addNode("photo", "mgnl:resource");
Binary binary = session.getValueFactory().createBinary(is);
nodeImage.setProperty("jcr:data", binary);
nodeImage.setProperty("jcr:mimeType", mtftm.getContentType(image));
String nomFichier = image.getName();
String nomFichierSansExtension = nomFichier.substring(0,
nomFichier.lastIndexOf('.'));
String extension = nomFichier.substring(nomFichier.lastIndexOf('.') + 1);
nodeImage.setProperty("filename", nomFichierSansExtension);
nodeImage.setProperty("extension", extension);
nodeImage.setProperty("size", Long.toString(image.length()));
nodeImage.setProperty("width", "130");
nodeImage.setProperty("height", "115");
nodeImage.setProperty("nodeDataTemplate", "");
IOUtils.closeQuietly(is);
session.save();
}
[/code]
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=3c12a79f-6909-469c-9f93-2f982920aabc
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------