msgraph-sdk-go-core icon indicating copy to clipboard operation
msgraph-sdk-go-core copied to clipboard

Issue creating upload session on a folder

Open MilitsaB opened this issue 1 year ago • 1 comments

I am trying to create an upload session to upload a file in a folder in Sharepoint. I am receiving the following error: Cannot create an upload session on a folder. I understand that an upload session cannot be created on a folder, however I am not sure how I can create one.

This is what I am currently doing:

uploadSession, err := graphClient.
		Drives().ByDriveId(driveID).
		Items().ByDriveItemId(folderID).
		CreateUploadSession().
		Post(ctx, uploadSessionRequestBody, nil)

I noticed that the msgraph-sdk-net has a method ItemWithPath which is not available in the Go version (https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1353)

var uploadSession = await graphClient.Sites["site-id"].Drive.Items["folderId"].ItemWithPath("file.txt")
                            .CreateUploadSession(uploadProps)
                            .Request()
                            .PostAsync();

Any ideas on how I can do this using msgraph-sdk-go?

MilitsaB avatar Oct 02 '24 21:10 MilitsaB

Hi @MilitsaB, thanks for trying out the SDK. Are you able to test this example i.e concatenate the folderID + itemPath + ":"


uploadSession, _ := graphClient.Drives().
    ByDriveId(*myDrive.GetId()).
    Items().
    ByDriveItemId(folderID + "/"+"file.txt"+":").
    CreateUploadSession().
    Post(context.Background(), uploadSessionRequestBody, nil)

rkodev avatar Oct 07 '24 12:10 rkodev

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.