【问题标题】:alfresco file Upload Unexpected error occurred during upload of new contentalfresco file Upload 上传新内容时发生意外错误
【发布时间】:2014-05-21 10:34:51
【问题描述】:

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

【问题讨论】:

标签: java json upload alfresco resttemplate


【解决方案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);

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2015-04-04
    • 2017-08-02
    • 2011-12-27
    相关资源
    最近更新 更多