繁体   English   中英

使用 Microsoft Graph SDK for java 将带有元数据的大文件上传到 SharePoint

[英]Uploading large file to SharePoint with metadata using Microsoft Graph SDK for java

通过MS Graph SDK(Java)将大文件上传到SharePoint Online(文档库)对我有用,但在上传时添加元数据似乎很难

我尝试在DriveItemUploadableProperties中添加元数据,因为我没有找到正确位置的任何提示

DriveItemUploadableProperties value = new DriveItemUploadableProperties();
value.additionalDataManager().put("Client",  new JsonPrimitive("Test ABC"));
    
var driveItemCreateUploadSessionParameterSet = DriveItemCreateUploadSessionParameterSet.newBuilder().withItem(value);

UploadSession uploadSession = graphClient.sites(SPValues.SITE_ID).lists(SPValues.LIST_ID).drive().root().itemWithPath(path).createUploadSession(driveItemCreateUploadSessionParameterSet.build()).buildRequest().post();
LargeFileUploadTask<DriveItem> largeFileUploadTask = new LargeFileUploadTask<>(uploadSession, graphClient, fileStream, streamSize, DriveItem.class);
    
LargeFileUploadResult<DriveItem> upload = largeFileUploadTask.upload(customConfig);

这导致400: Bad Request响应

如何以正确的方式在上传时添加元数据?

AFAIK,上传到 Sharepoint 时无法添加元数据。 您必须提出两个单独的请求,一个是上传文件,另一个是向您刚刚上传的文件添加其他元数据。

在添加您自己的自定义元数据之前,您必须将构面/架构注册到 OneDrive。 请参阅此文档:

https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/custom-metadata-facets?view=odsp-graph-online

但是您应该知道,由于自定义构面是预览版中的一项功能,因此在撰写本文时,您必须直接联系 MS email 并手动批准自定义构面,不幸的是,没有自动 API 可以做到这一点。

如果您以某种方式设法使自定义方面获得批准:

DriveItemUploadableProperties具有预设字段,例如文件名、大小等,用于表示上传任务和有关文件的基本详细信息,没有选项可以添加其他元数据。 请参阅DriveItemUploadableProperties的文档:

https://docs.microsoft.com/en-us/graph/api/resources/driveitemuploadableproperties?view=graph-rest-1.0

我假设当您说“通过 MS Graph SDK (Java) 将大文件上传到 SharePoint Online(文档库)对我有用”时,您能够成功上传文件并在来自上传的文件。 您可以使用项目 ID 通过第二个请求更新文件的元数据。 具体参考这里的更新驱动项:

https://docs.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

DriveItem driveItem = new DriveItem();
driveItem.name = "new-file-name.docx";

graphClient.me().drive().items("{item-id}")
    .buildRequest()
    .patch(driveItem);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM