How to get the uploaded file path in java file when action is called?

cancel
Showing results for 
Search instead for 
Did you mean: 
noohulalthaf
Active Member

How to get the uploaded file path in java file when action is called?

Hi,

I have written an action to extract the data from excel files which is uploaded in a folder. ie. a rule is created  like whenever the excel file is created in particular folder, the action is triggered  and the data from the excel file gets extracted and store in the listarray, i have done the action part, but need the uploaded file path to access the file uploaded in the folder contain rule. the action code is written in java.Any suggestion?

10 Replies
krutik_jayswal
Senior Member II

Re: How to get the uploaded file path in java file when action is called?

It seems like you are facing issues in accessing content of excel file.In alfresco you can get the content using eigther nodeService or contentService in alfresco.

Check alfresco foundation api for more details.

noohulalthaf
Active Member

Re: How to get the uploaded file path in java file when action is called?

Actually i am not facing any issues in accessing the content of excel file, the content gets stored in the list already, my problem is, as of now i am accessing excel file from local path and read the content and storing in listarray  when the action is triggered, but my requirement is to access the uploaded excel file path in document library of alfresco share?

Hope you understand my scenario.

krutik_jayswal
Senior Member II

Re: How to get the uploaded file path in java file when action is called?

nodeService.getPath(nodeRef) will return path of a node.

nodeService.getPaths(nodeRef, primaryOnly) will return path as a list.

noohulalthaf
Active Member

Re: How to get the uploaded file path in java file when action is called?

This is how i am getting the path parameter ,but getting 'Filenotfound' error, is this the right way to  get path parameter?

protected void executeImpl(Action arg0, NodeRef arg1) {

try {

Path path = nodeService.getPath(arg1) ;
System.out.print(path);
readFile(path);



} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

the error details as follows:

/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/site/1.0}sites/{http://www.alfresco.org/model/content/1.0}hexa/{http://www.alfresco.org/model/content/1.0}documentLibrary/{http://www.alfresco.org/model/content/1.0java.io.FileNotFoundException: \{http:\www.alfresco.org\model\application\1.0}company_home\{http:\www.alfresco.org\model\site\1.0}sites\{http:\www.alfresco.org\model\content\1.0}hexa\{http:\www.alfresco.org\model\content\1.0}documentLibrary\{http:\www.alfresco.org\model\content\1.0}Extract_x0020_Data\{http:\www.alfresco.org\model\content\1.0}EMSRaw-2.xlsx (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at com.hexa.action.executer.ExtractData.readFile(ExtractData.java:68)
at com.hexa.action.executer.ExtractData.executeImpl(ExtractData.java:36)
at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:267)
at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:839)
at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:66)
at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:267)
at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:839)
at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:740)
at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:574)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy65.executeAction(Unknown Source)
at org.alfresco.repo.rule.RuleServiceImpl.executeAction(RuleServiceImpl.java:1271)
at org.alfresco.repo.rule.RuleServiceImpl.executeRule(RuleServiceImpl.java:1265)
at org.alfresco.repo.rule.RuleServiceImpl.executePendingRuleImpl(RuleServiceImpl.java:1211)
at org.alfresco.repo.rule.RuleServiceImpl.executePendingRule(RuleServiceImpl.java:1154)
at org.alfresco.repo.rule.RuleServiceImpl.executePendingRulesImpl(RuleServiceImpl.java:1120)
at org.alfresco.repo.rule.RuleServiceImpl.executePendingRules(RuleServiceImpl.java:1093)
at org.alfresco.repo.rule.RuleTransactionListener.beforeCommit(RuleTransactionListener.java:57)
at org.alfresco.util.transaction.TransactionSupportUtil$TransactionSynchronizationImpl.doBeforeCommit(TransactionSupportUtil.java:535)
at org.alfresco.util.transaction.TransactionSupportUtil$TransactionSynchronizationImpl.doBeforeCommit(TransactionSupportUtil.java:514)
at org.alfresco.util.transaction.TransactionSupportUtil$TransactionSynchronizationImpl.beforeCommit(TransactionSupportUtil.java:479)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:925)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:738)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:482)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:479)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:580)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:649)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:421)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:301)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

krutik_jayswal
Senior Member II

Re: How to get the uploaded file path in java file when action is called?

Seems like the problem is in readFile(path); function.

As you have not posted content of readFile(path) function, i can not identify the issue.

but it seems that you are not clear on what is this path so below is details.

This path represents the path of alfresco, it is not actual physical path of your system which is "C:/User/Somehting" this.

So if you would like to read the file, then method of it in alfresco will be using alfresco foundation api.You can read it using nodeService ot contentService.

noohulalthaf
Active Member

Re: How to get the uploaded file path in java file when action is called?

I am not sure that the problem is with readfile(path) function, because the same function works when i try to read the file from local path ie. C:/test.xlsx, and i really not aware of how to get the file path when the action gets triggered when upload a file in alfresco.as you said the path which i am getting is not correct and i need the path to be like this format 

http://localhost:8080/share/page/site/hexa/document-details?nodeRef=workspace://SpacesStore/16ed82ce... 

So how i can access the path in executeImpl function when the file is uploaded in corresponding folder?can you guide me on that?

krutik_jayswal
Senior Member II

Re: How to get the uploaded file path in java file when action is called?

You can not access physical file path in alfresco.If you would like to read file refer below link for more details.

ContentService | Alfresco Documentation 

noohulalthaf
Active Member

Re: How to get the uploaded file path in java file when action is called?

This document talks about reading a content from a file, which is already done in my case. readfile(path) function is reading the file from the given path and giving the expected output. my problem is passing the parameter 'path' belong to be my uploaded path in alfresco.

if we cannot access the physical path in alfresco, what does nodeService.getPath(arg1) returns?

May be i am asking you silly question, i am trying to understand more.Sorry for that Smiley Happy

krutik_jayswal
Senior Member II

Re: How to get the uploaded file path in java file when action is called?

nodeService.getPath(arg1) will return logical path in alfresco, which you can browse in alfresco.Your readFile function is accessing physical path, so it will not work.

If you would like to read file in alfresco you need to read the documentation and try to understand it and design the function accordingly.

Smiley Happy