File upload using client credential workflow

Copper Contributor

I am writing a nodejs console application using client credentials workflow and I could hit and query drive/sharepoint apis. Now I want to upload large files. I referred these articles

And getting this error:
Error making Graph call: Error: /me request is only valid with delegated authentication flow.

Not sure where I am making /me call?! Any help would be much appreciated

// readFile from fs/promises
const file = await readFile(filePath);
// basename from path
const fileName = basename(filePath);

const options: OneDriveLargeFileUploadOptions = {
  // Relative path from root folder
  path: targetFolderPath,
  fileName: fileName,
  rangeSize: 1024 * 1024,
  uploadEventHandlers: {
    // Called as each "slice" of the file is uploaded
    progress: (range, _) => {
      console.log(`Uploaded bytes ${range?.minValue} to ${range?.maxValue}`);

// Create FileUpload object
const fileUpload = new FileUpload(file, fileName, file.byteLength);
// Create a OneDrive upload task
const uploadTask = await OneDriveLargeFileUploadTask.createTaskWithFileObject(

// Do the upload
const uploadResult: UploadResult = await uploadTask.upload();

// The response body will be of the corresponding type of the
// item being uploaded. For OneDrive, this is a DriveItem
const driveItem = uploadResult.responseBody as DriveItem;
console.log(`Uploaded file with ID: ${}`);


0 Replies