I'm bumping this thread because I want to be able to upload an image 
programmatically in 4.5.x. 
The method at the end of this post is almost working. After uploading an image 
with this method I see the thumbnail of the image in my content in 
adminCentral. 

But if I remove the image and replace it with another one in adminCentral the 
image thumbnail does not refresh itself. It take about 5 minutes for the 
thumbnail to refresh itself. This is probably cache related. Can anyone post an 
example to upload an image programmatically using a jcr.Node. I already know 
how to upload an image using Content and NodeData but I need to use deprecated 
methods on each line of code.


[code]
private boolean importerImage(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 filename = image.getName();
   String filenameWithoutExtension = filename.substring(0, 
filename.lastIndexOf('.'));
   String extension = filename.substring(filename.lastIndexOf('.') + 1);
   nodeImage.setProperty("filename", filenameWithoutExtension);
   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]>
----------------------------------------------------------------

Reply via email to