AnsweredAssumed Answered

how add file in alfresco with JCR ?

Question asked by wassim on Feb 24, 2009
Latest reply on Mar 6, 2010 by christianix
Hi,
I am trying to add a file (for example "pdf") to alfresco.
when I compile this code :


vJcrSession = vJcrRepository.login(new SimpleCredentials("admin", "admin".toCharArray()));
String fileName = "pdf/AlfrescoFAQ_1_1_FR.pdf";    
FileInputStream inputStream = new FileInputStream(fileName);
Node root = vJcrSession.getRootNode();
Node createdNodeRef = root.addNode(fileName, "nt:file");
Node dataNode = createdNodeRef.addNode("jcr:content", "nt:resource");
dataNode.setProperty("jcr:mimeType", "application/pdf");
dataNode.setProperty("jcr:encoding", "");
dataNode.setProperty("jcr:data", inputStream);
vJcrSession.save();


this is the error :



09:41:56,152 User:admin ERROR [alfresco.thread.WorkerThreadImpl] java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.thread.WorkerThreadImpl.run(WorkerThreadImpl.java:97)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
Caused by: javax.jcr.PathNotFoundException: Path 'pdf/AlfrescoFAQ_1_1_FR.pdf' does not exist from node workspace://Space
sStore/704b4554-30d2-4054-8502-6d52316b49df
        at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:166)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:138)
        at $Proxy175.addNode(Unknown Source)
        … 8 more
09:41:56,156  ERROR [alfresco.thread.WorkerThreadManager] error on dispatched method [addNode]
javax.jcr.PathNotFoundException: Path 'pdf/AlfrescoFAQ_1_1_FR.pdf' does not exist from node workspace://SpacesStore/704b
4554-30d2-4054-8502-6d52316b49df
        at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:166)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:138)
        at $Proxy175.addNode(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.thread.WorkerThreadImpl.run(WorkerThreadImpl.java:97)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
09:45:57,307  ERROR [alfresco.thread.WorkerThreadManager] Inactive worker thread removed from threadMap3
10:20:32,461  ERROR [transaction.SpringAwareUserTransaction.trace] Detected first UserTransaction which is being garbage
collected without a commit() or rollback()
10:20:32,461  ERROR [transaction.SpringAwareUserTransaction.trace] Logging of transaction call stack is now enabled and
will affect performance

Thank you for your help  :!:

Outcomes