microsoftgraph / microsoftgraph/msgraph-sdk-java

Copying File to another sharepoint destination

オープン
#2,338 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

status:waiting-for-triage type:bug
主要言語
Java
スター
444
フォーク
154
平均マージ
18時間 28分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。