alfresco file Upload上传新内容时发生意外错误

时间:2014-05-21 10:34:51

标签: java json upload alfresco resttemplate

我想使用后端Webscript将文件上传到alfresco:alfresco/service/api/upload。这是我如何构建我的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。当我运行应用程序时,我收到此错误:

  "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));。知道为什么吗?如果是别的请告诉我!

1 个答案:

答案 0 :(得分:1)

以下是我最后所做的工作:

 _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);

希望得到这个帮助。