【发布时间】: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));。知道为什么吗?如果是别的,请告诉我!
【问题讨论】:
-
你确定你应该发送那个 webscript JSON 吗?基于looking at the source code for it,似乎需要html表单字段来代替
标签: java json upload alfresco resttemplate