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);
希望获得帮助.