Forum Discussion

krisrajz721470's avatar
krisrajz721470
Copper Contributor
Jan 08, 2024

File upload using client credential workflow

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

https://learn.microsoft.com/en-us/graph/tutorials/typescript-app-only?tabs=aad&tutorial-step=5
https://learn.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=typescript

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(
  graphClient,
  fileUpload,
  options,
);

// 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: ${driveItem.id}`);

 

No RepliesBe the first to reply

Resources