-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Primary Intent:
Upload a file to OneDrive
What I have tried so far:
Application registration created in Azure AD with required permissions and secret.
Used the App Only Client Credentials flow to create NewClientSecretCredential and graph service client.
graphcred, err := azidentity.NewClientSecretCredential(
tenantID,
clientID,
clientSecret,
nil,
)
if err != nil {
log.Fatal(err)
}
grclient, err := msgraphsdk.NewGraphServiceClientWithCredentials(graphcred, []string{"https://graph.microsoft.com/.default"})
if err != nil {
log.Fatal(err)
}
I have used these client to Get details of the Drive as below where I want to upload the file.
result, err := grclient.Drives().ByDriveId(driveID).Get(context.Background(), nil)
if err != nil {
fmt.Printf("Error getting the drive: %v\n", err)
printOdataError(err)
}
fmt.Printf("Found Drive : %v\n", *result.GetId())
Following docs here : https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#create-an-upload-session I am trying to create an upload session
//Create an upload session
uploadSessionRequestBuilder := grclient.Drives().ByDriveId(driveID).Items().ByDriveItemId(filePath).CreateUploadSession()
I am able to get a response and print it.
log.Println(*uploadSessionRequestBuilder) //value below
`{{map[baseurl:https://graph.microsoft.com/v1.0 drive%2Did:xxxxxxx driveItem%2Did:file.txt] 0x1400012caf0 {+baseurl}/drives/{drive%2Did}/items/{driveItem%2Did}/createUploadSession}}`
Where is this struct defined/documented so I can understand what the fields are?
log.Printf("%T", uploadSessionRequestBuilder) //type: *drives.ItemItemsItemCreateUploadSessionRequestBuilder
I am unable to understand or move forward with how to use this uploadSessionRequestBuilder to actually upload the file to OneDrive.
Any help is much appreciated. Please advise if I should rather some other recommended sdk to programmatically upload files to OneDrive.