microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
370 stars 125 forks source link

byDriveItemId method items() works different in some cases in version 6.1.0 #1804

Open ihudedi opened 6 months ago

ihudedi commented 6 months ago

Hi I found the the method byDriveItemId ask for different path every time: To get drive item for item in root graphServiceClient.drives().byDriveId("driveId").items().byDriveItemId("root:/fileName").get()

To get drive item children in root : graphServiceClient.drives().byDriveId("driveId").items().byDriveItemId("root:/fileName:").get() Added colon in the end. same for when trying to upload file use with extra colon in the end graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId("root:/fileName:).content().put(fileContent) Didn't understand why there is a change in the logic.... Morethan it When transfer large item using UploadSession uploadSession = graphServiceClient.drives() .byDriveId("driveId") .items() .byDriveItemId("root:/fileName") .createUploadSession().post(uploadSessionPostRequestBody); Nothing is working with colon or without colon. Would like to know the logic Thanks, Itay

cschenkeltherolf commented 2 months ago

For the life of me, I can't figure out how to go from v3's upload behavior.

e.g. https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/root%3A%2F{file.docx}:/content

DriveItem fileDetails = Dependencies.getGraphServiceClient(documentStorageConfig) .drives() .byId(documentStorageConfig.getExternalStorageId()) .root() .itemWithPath(fileUploadUrl) .content() .buildRequest() .put(IOUtils.toByteArray(inputStream));

Where a file is put in the root folder of the destination drive.

in v6, trying with a url needs an absolute URL apparently

DriveItem fileDetails = Dependencies.getGraphServiceClient(documentStorageConfig) .drives() .byDriveId(documentStorageConfig.getExternalStorageId()) .root() .withUrl(fileUploadUrl) .content() .put(inputStream);

and even with e.g.:

"https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/root%3A%2F{file.docx}:/content" I get "com.microsoft.graph.models.odataerrors.ODataError: Entity only allows writes with a JSON Content-Type header."

and with something like:

DriveItem fileDetails = Dependencies.getGraphServiceClient(documentStorageConfig) .drives() .byDriveId(documentStorageConfig.getExternalStorageId()) .items() .byDriveItemId("root:/{file.docx}:") .content() .put(inputStream);

it just goes to "Shared Documents" rather than "Communication site > root" in Sharepoint.