jeudi 12 février 2015

Update metadata column using Java REST



As I understand, you have to make a 3 steps to update the metadata on the file. I have uploaded a file to my document library using POST and after that made a GET and took out the metadata i need to change, in this case "Title". The next step is to make a PUT and send the metadata with it but how? I don't want to implement Microsofts classes.


Here is the code to upload a file:


documentLibrary = sharepoint server url to document library

http://industrial-ex/sites/tifdemo/enovia/


enoviaDocument = local path to a file

D:\tif-destination


if (enoviaDocument.isFile()) {

FileInputStream fileInputStream = new FileInputStream(enoviaDocument); PostMethod method = new PostMethod(documentLibrary + enoviaDocument.getName()); RequestEntity requestEntity = new InputStreamRequestEntity(fileInputStream); method.setRequestEntity(requestEntity); authentication.getHttpClient().executeMethod(method); System.out.println("STATUS CODE: " + method.getStatusCode() + " " + "STATUS TEXT: " + method.getStatusText()); System.out.println("STATUS LINE: " + method.getStatusLine());


Here is the code to get file:


String url = "http://industrial-ex/sites/tifdemo/_api/web/lists/getbytitle('enovia')/items/"; GetMethod get = new GetMethod(url); get.setRequestHeader("Accept", "application/json; odata=verbose;"); authentication.getHttpClient().executeMethod(get); JsonParser jsonParser = new JsonParser(); JsonElement jsonElement = jsonParser.parse(get.getResponseBodyAsString()); JsonObject asJsonObject = jsonElement.getAsJsonObject(); String title = asJsonObject.get("d") .getAsJsonObject() .get("results") .getAsJsonArray() .get(0) .getAsJsonObject() .get("Title") .getAsString(); System.out.println("Metadata Title: " + title);


The next step is to make a PUT with metadata but how?








0 commentaires:

Enregistrer un commentaire