Question

I am learning magnolia cms. I am trying to use the resources module. I have actually 2 problems.

  1. Cannot upload a bunch of files. I have a few files, but in some time I will have to upload some more. Modules import feature wants me to upload an xml file. But I don't know how to generate it properly. Tried to import through JCR, but after that I can't see those files in resources app. Tried to configure the module to search files in file system: I set fileSystemLoader to class info.magnolia.module.resources.loaders.FileSystemResourceLoader and set some path. It did not work for me too. Maybe I just don't understand at what time should be activated files upload feature. At the application start up time it did not work.

  2. How to properly use these resources in my template? What ftl tag should I use?

I don't use STK module.

Thanks for your patience if you decide to help me.

Magnolia version: 5.2 CE

JDK iced tea: 1.7.0_51

OS: Linux/OpenSUSE 12.3

Was it helpful?

Solution

I've used previously (on 4.5.x) script below to perform the task via groovy module. It should work on 5.2 as well.

import static groovy.io.FileType.FILES
import info.magnolia.jcr.util.NodeUtil
import org.apache.commons.lang.StringUtils
import info.magnolia.cms.util.ContentUtil

class Globals {
 static def folderName = '//some/folder/in/filesystem/on/server'
}

def loadImageFolder() {
 session = ctx.getJCRSession("resources")
 parentFolder = session.getNode("/templating-kit/jelinek-image/obrazky-produkty")

 new File(Globals.folderName).eachFileRecurse(FILES) {

  name = it.name
  // set file name
  extension = StringUtils.substringAfterLast(name, '.')
  name = StringUtils.substringBeforeLast(name, '.')

  // persist
  resource = NodeUtil.createPath(parentFolder,name , "mgnl:content")
  // persistResource
  resource.setProperty("mgnl:template", "resources:binary")
  resource.setProperty("extension", extension)

  binary = resource.addNode("binary", "mgnl:resource")
  binary.setProperty("jcr:data", new FileInputStream(it.absolutePath))
  binary.setProperty("extension", extension)
  binary.setProperty("fileName", name)
  binary.setProperty("jcr:mimeType", "image/"+extension)
  binary.setProperty("size", it.length())

 }
 session.save()
}

loadImageFolder() 
return 'done'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top