上传包含元数据/更新文档的文档 - Sharepoint 2010 Rest API

时间:2017-04-06 12:28:10

标签: java rest sharepoint sharepoint-2010 metadata

我需要在Java EE项目(Spring MVC)中上载Sharepoint Foundation 2010上的文档。我使用HttpClient与Sharepoint 2010 rest API进行交互,一切运行良好,但我有两个问题:

  • 如何上传包含元数据的文档?目前,我上传文档并在上传完成后更新元数据。由于该方法,我的文档自动在2.0版本中,它不是最佳行为......
  • 如何更新文件?我知道如何更新元数据,但我没有想法更新文档本身。

我的上传:

    DefaultHttpClient httpClient = new DefaultHttpClient();
    NTCredentials credentials = new NTCredentials(this.username, this.password, "", "");
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);

    String url = "[url to library api - ..../ListData.svc/library]";
    String slug = "[url to document]";

    HttpPost post = new HttpPost(url);
    post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    post.setHeader("Content-Type", "multipart/form-data");
    post.setHeader("Accept", "application/json; charset=utf-8; odata=verbose");
    post.setHeader("Slug", slug);

    MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    multipartContent.addPart(file.getName(), new FileBody(file));
    post.setEntity(multipartContent);

    HttpResponse response = httpClient.execute(post);

我的元数据更新:

    DefaultHttpClient httpClient = new DefaultHttpClient();
    NTCredentials credentials = new NTCredentials(this.username, this.password, "", "");
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);

    String url = "[url to document API - ....ListData.svc/library(ID)]";

    HttpPost post = new HttpPost(url);
    post.setHeader("Content-Type", "application/json");
    post.setHeader("Accept", "application/json; charset=utf-8; odata=verbose");
    post.setHeader("X-HTTP-Method", "MERGE");
    post.setHeader("If-Match", etag);

    post.setEntity(new StringEntity("[JSON update metadata]", ContentType.APPLICATION_JSON));

    HttpResponse response = httpClient.execute(post);

0 个答案:

没有答案