alfresco文件上载新内容期间发生意外错误 [英] alfresco file Upload Unexpected error occurred during upload of new content

查看:304
本文介绍了alfresco文件上载新内容期间发生意外错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用后端Webscript alfresco/service/api/upload将文件上传到露天.这是我构建json的方法:

I want to upload a file to alfresco using the backend Webscript: alfresco/service/api/upload. Here is how I build my json:

_ticket = Login.getAlfTicket(login, psswd);
String url = "http://localhost:8080/alfresco/service/api/upload";

File file = new File("C:/the-file-name.txt");
byte[] bytes = Files.readAllBytes(file.toPath());
bytes = Base64.encodeBase64(bytes);
JSONObject json = new JSONObject();
json.put("filedata", new String(bytes));
json.put("siteid", "google");
json.put("containerId", "documentLibrary");
json.put("uploadDirectory", "/test");

我使用RestTemplate发布我的json.当我运行应用程序时,出现此错误:

I use RestTemplate to POST my json. when I run the application I get this error :

  "status" : 
 {
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
 },  

 "message" : "04210030 Unexpected error occurred during upload of new content.",  
 "exception" : "org.springframework.extensions.webscripts.WebScriptException - 04210030 Unexpected error occurred during upload of new content.",

 "callstack" : 
 [ 
  ""      ,"org.mozilla.javascript.JavaScriptException: [object Error] (file:\/C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/upload\/upload.post.js#405)"
  ,"org.mozilla 
.....

我知道问题出在这部分:json.put("filedata", new String(bytes));.知道为什么吗?如果还有其他事情,请告诉我!

I know that the problem come from this part : json.put("filedata", new String(bytes));. Any idea why ? if it is something else please let me know !

推荐答案

这是我最后使它起作用的方法:

Here is what I did at the end to make it work :

 _ticket = Login.getAlfTicket("admin", "alfresco");
String url = "http://localhost:8080/alfresco/service/api/upload";

MultiValueMap<String, Object> request = new LinkedMultiValueMap<String, Object>();
FileSystemResource rsc = new FileSystemResource("<PATH_TO_FOLDER>/the-file-name.txt");

request.add("filedata", rsc);
request.add("siteid", "yoursite");
request.add("containerid", "documentLibrary");
request.add("uploaddirectory", "test");

//restTemplate is an instance of RestTemplate class
restTemplate.postForEntity(url + "?alf_ticket=" + _ticket, request,
      String.class);

希望获得帮助.

这篇关于alfresco文件上载新内容期间发生意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆