Hello Daniel,
As far as i know there's no such code in Magnolia 5 DAM module. I searched for
it a while ago and created JIRA MGNLDAM-326 which has been closed since and
replaced with MGNLDAM-359 which has been open for two years now.
By the way, i needed to upload files into asset nodes, so here is the method
i've created in a custom DamUtil class.
[code]
public void setFile(final Node assetNode, final File file) throws
RepositoryException, FileNotFoundException {
// Get or add resource node
final Node resourceNode = JcrUtils.getOrAddNode(assetNode,
AssetNodeTypes.AssetResource.RESOURCE_NAME,
AssetNodeTypes.AssetResource.NAME);
// Read file
InputStream input = new FileInputStream(file);
try {
final Binary binary =
ValueFactoryImpl.getInstance().createBinary(input);
resourceNode.setProperty(JcrConstants.JCR_DATA, binary);
} finally {
IOUtils.closeQuietly(input);
}
// Set file properties
resourceNode.setProperty(FileProperties.PROPERTY_FILENAME,
file.getName());
final String extension =
FilenameUtils.getExtension(file.getName());
resourceNode.setProperty(FileProperties.PROPERTY_EXTENSION,
extension);
resourceNode.setProperty(FileProperties.PROPERTY_SIZE,
Long.toString(file.length()));
final String mimetype =
StringUtils.defaultIfEmpty(MIMEMapping.getMIMEType(extension),
"application/octet-stream");
resourceNode.setProperty(FileProperties.PROPERTY_CONTENTTYPE,
mimetype);
// Set image width and height
input = new FileInputStream(file);
try {
final ImageInfo imageInfo = new ImageInfo();
imageInfo.setInput(input);
if (imageInfo.check()) {
resourceNode.setProperty(FileProperties.PROPERTY_WIDTH,
Long.toString(imageInfo.getWidth()));
resourceNode.setProperty(FileProperties.PROPERTY_HEIGHT,
Long.toString(imageInfo.getHeight()));
}
} finally {
IOUtils.closeQuietly(input);
}
}
[/code]
Hope this will help. Don't forget to save the JCR session.
Best regards,
Vincent
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=8a22aaec-21e8-487a-b0ee-319409bd4fdb
----------------------------------------------------------------
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]>
----------------------------------------------------------------