Hi @Gal, Ofer ,
Usually, we instantiate MSGraphClient object from SharePoint context like this:
import { MSGraphClient } from '@microsoft/sp-http';
const msGraphClient=this.context.msGraphClientFactory.getClient();
However, you are using const uploadTask: OneDriveLargeFileUploadTask = await OneDriveLargeFileUploadTask.create(client, file, options);
. The Client instance in the code is different from msGraphClient instance .
You have to instantiate a Client object as I mentioned above, below is my sample code:
First, npm install msal
Then:
import { UserAgentApplication } from "msal";
import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider";
import { MSALAuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions';
import {Client, OneDriveLargeFileUploadTask} from "@microsoft/microsoft-graph-client";
const msalConfig = {
auth: {
clientId: "your_client_id", // Client Id of the registered application
redirectUri: "your_redirect_uri",
},
};
const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication
const msalApplication = new UserAgentApplication(msalConfig);
const options = new MSALAuthenticationProviderOptions(graphScopes);
const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, options);
const client = Client.initWithMiddleware({
debugLogging: true,
authProvider: authProvider,
});