我正在尝试更新Alfresco中的文件…,然后执行以下代码:
var csrf_header = Alfresco.util.CSRFPolicy.getHeader(); var csrf_token = Alfresco.util.CSRFPolicy.getToken(); function getResponse(pdfbase64) { var fd = new FormData(); if (Alfresco.util.CSRFPolicy && Alfresco.util.CSRFPolicy.isFilterEnabled()) { fd.append(csrf_header, csrf_token); } fd.append("username", "admin"); fd.append("updatenoderef", nodeRef); fd.append("filedata", pdfbase64); fd.append("majorversion", "true"); fd.append("overwrite", "true"); alert(fileUpdateURL); $.ajax({ url: fileUpdateURL, type: "POST", data: fd, processData: false, // tell jQuery not to process the data contentType: false // tell jQuery not to set contentType }); }
变量pdfbase64是把该文件(的变化,我对文件进行更新以base64文件)的内容,但也许这是不正确的格式?nodeRef是的文件,如参考:"workspace://SpacesStore/4fb1b7e7-2502-4011-8870-17e8d626b93b"和fileUpdateURL是URL对POST:http://localhost:8080/share/proxy/alfresco/api/upload
pdfbase64
nodeRef
"workspace://SpacesStore/4fb1b7e7-2502-4011-8870-17e8d626b93b"
fileUpdateURL
URL
POST
http://localhost:8080/share/proxy/alfresco/api/upload
参数来源
我得到了错误:
POST http:// localhost:8080 / share / proxy / alfresco / api / upload 500内部服务器错误 javax.servlet.ServletException:比较会话和请求参数中的令牌时,注意到可能的CSRF攻击。要求:在org.alfresco.web.site.servlet.CSRFFilter $ AssertTokenAction.run(CSRFFilter.java:845)上的POST / share / proxy / alfresco / api / upload在org.alfresco.web.site.servlet.CSRFFilter.doFilter (CSRFFilter.java:312)在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)在org.alfresco。 web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:447) 在org.apfc.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)在org.alfresco.web.site.servlet.MTAuthenticationFilter org上的org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)的.doFilter(MTAuthenticationFilter.java:74)org上的org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)的apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase。 java:504),网址为org.apache.catalina.core.StandardHostValve。在org.apache处org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)处调用(StandardHostValve.java:170)在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)处org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)上的.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java) :1074),位于org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466),位于org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466),位于org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)。 tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2455)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)位于org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)位于java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) .run(Thread.java:745)
POST http:// localhost:8080 / share / proxy / alfresco / api / upload 500内部服务器错误
javax.servlet.ServletException:比较会话和请求参数中的令牌时,注意到可能的CSRF攻击。要求:在org.alfresco.web.site.servlet.CSRFFilter $ AssertTokenAction.run(CSRFFilter.java:845)上的POST / share / proxy / alfresco / api / upload在org.alfresco.web.site.servlet.CSRFFilter.doFilter (CSRFFilter.java:312)在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)在org.alfresco。 web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:447)
在org.apfc.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)在org.alfresco.web.site.servlet.MTAuthenticationFilter org上的org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)的.doFilter(MTAuthenticationFilter.java:74)org上的org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)的apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase。 java:504),网址为org.apache.catalina.core.StandardHostValve。在org.apache处org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)处调用(StandardHostValve.java:170)在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)处org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)上的.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java) :1074),位于org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466),位于org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2466),位于org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)。 tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2455)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)位于org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)位于java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) .run(Thread.java:745)
编辑:如果我使用
http:// localhost:8080 / alfresco / service / api / upload
代替
http:// localhost:8080 / share / proxy / alfresco / api / upload
我得到错误:
{ "status" : { "code" : 400, "name" : "Bad Request", "description" : "Request sent by the client was syntactically incorrect." }, "message" : "Required parameters are missing", "exception" : "", "callstack" : [ ], "server" : "Community v5.0.0 (d r99759-b2) schema 8,022", "time" : "Jan 24, 2016 1:14:41 PM" }
谁能帮我?
编辑2:
我尝试使用以下命令通过http:// localhost:8080 / share / proxy / alfresco / api / upload发出请求:
function getResponse(pdfbase64) { var csrf_header = Alfresco.util.CSRFPolicy.getHeader(); var csrf_token = Alfresco.util.CSRFPolicy.getToken(); var fd = new FormData(); if (Alfresco.util.CSRFPolicy && Alfresco.util.CSRFPolicy.isFilterEnabled()) { fd.append(csrf_header, csrf_token); fileUpdateURL += "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken()); } fd.append("username", "admin"); fd.append("updatenoderef", nodeRef); fd.append("filedata", pdfbase64); fd.append("majorversion", "true"); fd.append("overwrite", "true"); alert(fileUpdateURL); $.ajax({ url: fileUpdateURL, type: "POST", data: fd, processData: false, // tell jQuery not to process the data contentType: false // tell jQuery not to set contentType }); }
但是我得到了错误:
尝试在函数中移动这些行:
var csrf_header = Alfresco.util.CSRFPolicy.getHeader(); var csrf_token = Alfresco.util.CSRFPolicy.getToken();
如果这不能解决您的问题,并且问题不是csrf_*vars 的可变范围问题,则应从此处尝试使用提示(2)
csrf_*
更新: 正如我在聊天中解释的那样,您应该替换:
fd.append("filedata", pdfbase64);
与:
fd.append("filedata", new Blob([pdfbase64], {type: 'application/pdf'}););