Created
March 7, 2024 15:38
-
-
Save aborroy/0ec4c96896b7c0da88badc7fdd05bf55 to your computer and use it in GitHub Desktop.
Encode to Base64 the content of an Alfresco node using Repository JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
| var contentService = ctxt.getBean('contentService', Packages.org.alfresco.service.cmr.repository.ContentService); | |
| var inputStream = contentService.getReader( | |
| new org.alfresco.service.cmr.repository.NodeRef(document.nodeRef), | |
| org.alfresco.service.namespace.QName.createQName(org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI, "content")).getContentInputStream(); | |
| var base64Content = java.util.Base64.getEncoder().encodeToString(org.apache.commons.io.IOUtils.toByteArray(inputStream)); | |
| logger.log(base64Content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment