我正在尝试使用以下方法将文件上传到 DocLibrary 文件夹:
private static void postTheDocument() {
final String restENDPoint = "http://servername:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/48eea6b2-fe9b-4cd2-8270-5caa35d7e8dc/children";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setBasicAuth("admin", "admin");
String requestJson = "{\"name\": \"TestName123s.doc\",\"nodeType\": \"hr:HR_Type\",\"properties\":{\"cm:title\":\"New Test title123\",\"hr:emp_no\":\"123456\",\"hr:lname\":\"Last_Name1\",\"hr:fname\":\"First_Name1\"}}";
HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);
HttpEntity<String> response = restTemplate.exchange(restENDPoint, HttpMethod.POST, entity,
String.class);
System.out.println(response.getBody().toString());
}
文档建议这样做:
curl -utest:test -X POST host:port/alfresco/api/-default-/public/alfresco/versions/1/nodes/12341234-2344-2344-43243242334/children -F filedata=@test.txt
使用 postTheDocument() 方法创建空文档。但是当我尝试以下请求时:
String requestJson = "{\"filedata\": \"@Z:/05test/YYYYest11qq890.pdf\",\"name\": \"TestName123s.doc\",\"nodeType\": \"hr:HR_Type\",\"properties\":{\"cm:title\":\"New Test title123\",\"hr:emp_no\":\"123456\",\"hr:lname\":\"Last_Name1\",\"hr:fname\":\"First_Name1\"}}";
我得到以下异常:
Exception in thread "main" org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"error":{"errorKey":"Could not read content from HTTP request body: Unrecognized field \"filedata\" (class org.alfresco.rest.api.model.Node), not marked as ignorable (36 known properties: \"modifiedB... (1969 bytes)]
我在这里做错了什么或我错过了什么?