簡體   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