microsoftgraph / microsoftgraph/msgraph-sdk-java

Copying File to another sharepoint destination

未關閉
#2,338 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

status:waiting-for-triage type:bug
主要語言
Java
星號
444
分支
154
平均合併
18 小時 28 分鐘
30 天內合併 PR
4

描述

Describe the bug

HI ,
I am copying a file from my sharepoint site to another location on the same site.
The first time i execute the code the file is copied correctly.
When i change the file content in the source folder and copy it again the code executes without errors but
the new file is not copied. In the destination folder there is still the file that was initialy copied.

I read the docs : https://learn.microsoft.com/en-us/graph/api/driveitem-copy?view=graph-rest-1.0&tabs=http
According to the docs i can use @microsoft.graph.conflictBehavior to replace the file in the destination but this does not work. The file is only copied once. When i delete the file in the destination the file is copied again.

This is the code i use.
Be sure that the referenced ids in the snipplet are fine and that in copyPostRequestBody the copyPostRequestBody.setParentReference(itemRefDestination); is set correctly.

DriveItem created = authenticationProvider.getGraphServiceClient().drives().byDriveId(driveRoot.getId()).items()
.byDriveItemId(driveItem.getId()).copy()
.post(copyPostRequestBody);

The other question i have here is: Why is "DriveItem created" always null ? According to the SDK post(...) returns a DriveItem. No matter if the copy is made (in the first place) or not the returned object is always null.

How can i make sure that changes made on the file in the source folder are always copied?

Expected behavior

I expect the file to be copied and the conflict behaviour provided is applied. As in when "replace" than its replaced , when "rename" the file is renamed in the destination.

How to reproduce
// get the source file as DriveItem 
DriveItem sourceItem= driveItemManager.getDriveItemByPath(source.getPath());

// get the destination location as DriveItem 
DriveItem destinationRoot = driveItemManager.getDriveItemByPath(destination.getPath());

// create ItemReference  from destination root.
 ItemReference itemRefDestination = new ItemReference();
    itemRefDestination.setDriveId(driveItemDest.getParentReference().getDriveId());
    itemRefDestination.setId(driveItemDest.getId());
    itemRefDestination.setName(destination.getName());

// create CopyPostRequestBody and set reference.
    CopyPostRequestBody copyPostRequestBody = new CopyPostRequestBody();
    copyPostRequestBody.setParentReference(itemRefDestination);

//execute the copy call -> myDriveId
DriveItem post = authenticationProvider.getGraphServiceClient().drives().byDriveId(myDriveId).items()
                        .byDriveItemId(sourceItem.getId()).copy()
                        .post(copyPostRequestBody);
SDK Version

6.33.0

Latest version known to work for scenario above?

5.80.0

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

Windows 11

### Other information

_No response_

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 DriveItem copy().post(...) 進入點以及 issue 中連結的 Microsoft Graph driveItem copy 文件開始。使用提供的 source、destination、ItemReference 和 CopyPostRequestBody 程式碼重現該情境,接著判斷為什麼未套用取代,以及為什麼 post() 回傳 null。當所回報的複製行為和回傳值已獲得解釋或修正時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api, cloud
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。