question

GalOfer-7756 avatar image
0 Votes"
GalOfer-7756 asked MichaelHan-MSFT answered

"Namespace "{mypath}/node_modules/@microsoft/microsoft-graph-types/microsoft-graph"' has no exported member 'OneDriveLargeFileUploadTask' .ts(2694)"

Following https://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=typescript, Typescript complains that it can't fine "OneDriveLargeFileUploadTask"
I have imports

import {Client} from "@microsoft/microsoft-graph-client"
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types"


How do I get the code to work?

office-sharepoint-server-development
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I figured out that the example code is wrong:
const uploadTask: MicrosoftGraph.OneDriveLargeFileUploadTask = await MicrosoftGraph.OneDriveLargeFileUploadTask.create(client, file, options);
Should be:
import {Client, OneDriveLargeFileUploadTask} from "@microsoft/microsoft-graph-client"
Then
const uploadTask: OneDriveLargeFileUploadTask = await OneDriveLargeFileUploadTask.create(client, file, options);
But I have trouble converting
MSGraphClient } from "@microsoft/sp-http";
that is provided by SPFx, to
Client from "@microsoft/microsoft-graph-client"

Anyone can help?

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered GalOfer-7756 commented

Hi @GalOfer-7756,

You're right. import {Client, OneDriveLargeFileUploadTask} from "@microsoft/microsoft-graph-client" works.

Did you mean initialize client in @microsoft/microsoft-graph-client?

 import { Client } from "@microsoft/microsoft-graph-client";
    
 const options = {
     authProvider, // An instance created from previous step
 };
 const client = Client.initWithMiddleware(options);

You could refer to the below articles for more:
https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/HEAD/docs/CreatingClientInstance.md
https://www.npmjs.com/package/@microsoft/microsoft-graph-client


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is there a simpler way to instantiate a client from SharePoint context inside a SPFx web part?
Is there an example somewhere?

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered

Hi @GalOfer-7756,

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,
       });







5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.