Log In | Sign Up   View a printable version of the current page.
  Dashboard > [fleXive] > ... > How-Tos > Import a folder of images on the server > Information > Page Comparison

compared with
Current by Daniel Lichtenberger
on Sep 14, 2009 11:35.

(show comment)
 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 1 changes. View first change.

 h3. Overview
  
 For testing purposes it can be useful to import a folder of images automatically. This Groovy script imports all files of a folder (on the server) as instances of the predefined Image type.
  
 h3. Executing the code
  
 Open the backend administration with a user who can execute scripts in the Groovy console, and open {{Scripts/Script Console}}. Check the "Execute at Web layer" box to use one transaction per image import (otherwise timeouts may occur). Copy and paste the code below and click execute. The import messages are written to stdout.
  
 h3. Code
  
 {code}
 import com.flexive.shared.*
 import com.flexive.shared.content.*
 import com.flexive.shared.value.*
 import com.flexive.shared.exceptions.*
 import java.io.FileInputStream
 import com.flexive.shared.scripting.groovy.GroovyContentBuilder
  
 new File("/path/to/images").eachFile { file ->
  if (file.directory) {
  return;
  }
  def builder = new GroovyContentBuilder("IMAGE")
  try {
  builder {
  imageBinary(new FxBinary(false, new BinaryDescriptor(file.name, new FileInputStream(file))))
  }
  EJBLookup.contentEngine.save(builder.getContent())
  println "Imported " + file.name
  } catch (Exception e) {
  println "Failed to import file: " + e
  }
 }
 {code}
  
 h3. Import a folder hierarchy
  
  See [Import a folder structure of documents on the server] for an example of how to traverse a folder structure recursively.
  Take a look at [Import a folder structure of documents on the server] for an example of how to traverse a folder structure recursively.
Site running on a free Atlassian Confluence Open Source Project License granted to [fleXive] . Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.1 Build:#916 Nov 09, 2007) - Bug/feature request - Contact Administrators