cancel
Showing results for 
Search instead for 
Did you mean: 

adding binary content

rcortesr
Star Contributor
Star Contributor
I need to add binary content to my customized type.
I do it like in the example of wikiExample but the execution does not finish!!
This is my code:
[size=75]
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:org/alfresco/sample/jcr/facturaModel-context.xml");
          
           // Retrieve Repository
           Repository repository = (Repository)context.getBean("JCR.Repository");

           // Login to workspace
           // Note: Default workspace is the one used by Alfresco Web Client which contains all the Spaces
           //       and their documents
           Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
          
           // Retrieve a node
            Node myNode = (Node) session.getItem("app:company_home");
            System.out.println("Company home node: path=" + myNode.getPath() + ", type=" + myNode.getPrimaryNodeType().getName());
           

            Node facturas = myNode.addNode("fac:facturas", "cm:folder");
         facturas.setProperty("cm:name", "Facturas");
            facturas.setProperty("cm:description", "");
           
            do
         {
            line = buffer.readLine(); //leo la primera linea
            if(line == null) break;
            x.parsear(line); //parseo la siguiente linea
            Node fac1 = facturas.addNode("fac:entry" + cnt, "fac:factura");
               for(int i=0;i<4;i++)
               {
                  if(i == 3) //añado el contenido, la imagen escaneada
                  {
                     //fac1.setProperty("cm:content", resource.getInputStream());
                  }
                  else
                  {
                     fac1.setProperty(campos[i], x.lista[i]); //Add a property
                  }
               }
               session.save(); //Persist the changes mySession.save();
               cnt++;
         }while(true);
            session.logout();
            System.out.println("¡¡¡Transferencia Completada!!!");
            System.exit(0);
[/size]

I have another question, why when I execute wikiExample appears the following error?
[size=75]Exception in thread "main" java.io.FileNotFoundException: class path resource [org/alfresco/jcr/example/wikiImage.gif] cannot be opened because it does not exist
   at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
   at org.alfresco.sample.jcr.WIKIExample.main(WIKIExample.java:145)
[/size]
3 REPLIES 3

davidc
Star Contributor
Star Contributor
Please make sure you're exiting your do { … } while (true) loop.

Exception in thread "main" java.io.FileNotFoundException: class path resource [org/alfresco/jcr/example/wikiImage.gif] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
at org.alfresco.sample.jcr.WIKIExample.main(WIKIExample.java:145)

The wikiImage.gif is not in your classpath directory org/alfresco/jcr/example.

rcortesr
Star Contributor
Star Contributor
The loop is correct.
In my SDK doesn't exist this path org/alfresco/jcr/example.
My image stay in org/alfresco/sample/jcr.
I have created this folder and I have copied the image but the error persists.

Thanks

rcortesr
Star Contributor
Star Contributor
Solved problem!!
In WIKIExample the path of the image isn't correct.
ClassPathResource resource = new ClassPathResource("org/alfresco/jcr/example/wikiImage.gif");

The path is:
ClassPathResource resource = new ClassPathResource("org/alfresco/sample/jcr/wikiImage.gif");

Thanks for all.